Using psexec.exe in jenkins, handle is invalid

14,248

Thanks to all your help, especially Technext, I have a solution.

I needed run "services.msc", find "Jenkins", right click on it, and go to "Properties". Once the properties windows appeared, I had to click the "Stop" button to stop Jenkins, open the "Log On" tab, enter in my username and password (the username I used when running through command prompt), and start Jenkins again. That got rid of the "handle is invalid" message in Jenkins.

Update: A better solution was to go onto the system I was using psexec.exe to get onto, go to Control Panel > User Accounts > Give other users access to this computer. Click on "Add..." and type in the username and domain Jenkins uses to run its commands (to find this, open your Jenkins in a browser window, go to Manage Jenkins > System Information and look for USERNAME and USERDOMAIN under Environment Variables). Make sure you give it Administrator rights. Then click ok. Now psexec.exe shouldn't have the "handle is invalid" issue.

Share:
14,248
headinabook
Author by

headinabook

BIOS Engineer.

Updated on August 08, 2022

Comments

  • headinabook
    headinabook over 1 year

    I am using Jenkins on a Windows7 system. I would like to use it to execute a batch script on a remote Windows system. The batch script will be used to flash a development board and run some tests. I came across psexec.exe. That works well through a command prompt window--I can connect and run the script without any issues, but when I try to have Jenkins do it, I get the following output:

    PsExec v2.11 - Execute processes remotely
    Copyright (C) 2001-2014 Mark Russinovich
    Sysinternals - www.sysinternals.com
    
    The handle is invalid.
    Connecting to ABCDEFG...
    
    Couldn't access ABCDEFG:
    Connecting to ABCDEFG...
    
    Build step 'Execute Windows batch command' marked build as failure
    

    The command I am using in both cases is: psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" "C:\test.bat"

    The user associated with username has administrator privileges on the remote system (ABCDEFG is not the real name of the system).

    Can anyone help me figure out why it is not working through Jenkins? Or, is there an easier/better way to execute a batch script on a remote Windows system through Jenkins?

  • headinabook
    headinabook over 9 years
    The @ tag with the txt file did not work. I got the same "handle is invalid" response.
  • Admin
    Admin over 9 years
    can the user running jenkins do the command, since I had some problems where psexec fails with user even though -u domain\user was correct. As i have now the user running jenkins does -u domain\user with itself as user. It was something about psexec first trying with the user it runs as, and then trying with the given credentials, but failing at first and giving up, don't remember the exact reason.
  • Daniel Gray
    Daniel Gray over 9 years
    This was it. Thanks a lot for sharing your answer!
  • Wouter van Rij
    Wouter van Rij almost 5 years
    Had a very similar issue, the service account that was running Jenkins was already an indirect member (via another security group) of the local Administrator group on the remote machine, however I had the exact same error. Adding the Jenkins Service account directly to the local Administrator group solved the issue for me.
  • Po-Sen Huang
    Po-Sen Huang over 3 years
    @headinabook Hi, I don't know how to find 'Give other users access to this computer' on windows server 2012 R2, could you tell me?