Using psexec.exe in jenkins, handle is not valid

I am using Jenkins on a Windows7 system. I would like to use it to execute a script package on a remote Windows system. The script package will be used to flash the development board and run some tests. I have encountered psexec.exe. This works well through the command line window - I can connect and run the script without any problems, but when I try to get Jenkins to do this, 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 use in both cases is: psexec.exe \\ ABCDEFG -u "DOMAIN \ username" -p "password" "C: \ test.bat"

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

Can someone help me understand why it is not working through Jenkins? Or is there an easier / better way to execute a batch script package on a remote Windows system via Jenkins?

+6
source share
3 answers

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

I need to run "services.msc", find "Jenkins", right-click on it and go to "Properties". When the property windows appeared, I had to click the Stop button to stop Jenkins, open the Login tab, enter my username and password (the username that I used when running the command line), and start Jenkins again. This eliminated the "handle is invalid" message in Jenkins.

Update: The best solution was to go to the system where I used psexec.exe to go to Control Panel> User Accounts> Grant other users access to this computer. Click "Add ..." and enter the Jenkins username and domain to use his commands (to find this, open Jenkins in a browser window, go to "Manage Jenkins"> "System Information" and find USERDOMAIN in the "Environment Variables" section "). Be sure to specify administrator rights. Then click OK. Now psexec.exe should not have a "handle" problem.

+4
source

Sorry, I don't have enough reputation for comment, but is this a single \ a typo? As

Invalid handle.

probably means that the computer address is not valid. Try

  psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" "C:\test.bat" 

Note the backslash for accessing a locally displayed computer.

otherwise, if this does not work, I recommend @tag

 psexec.exe @servername.txt -u "DOMAIN\username" -p "password" "C:\test.bat" 

where @ servername.txt is a text file containing only server names, one on each line. File option handles formatting \

ex servername.txt

 ABCDEFG COMPUTER2 

EDIT: also detected after a quick search on the Internet, which may be related to Windows protection .

0
source

Verify that just restarting the remote machine does not solve the problem. In addition, adding the -h and -accepteula options may help. Modified command:

psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" -h -accepteula "C:\test.bat"

0
source

Source: https://habr.com/ru/post/973575/


All Articles