Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using psexec.exe in jenkins, handle is invalid

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?

like image 859
headinabook Avatar asked Aug 08 '14 23:08

headinabook


1 Answers

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.

like image 128
headinabook Avatar answered Oct 19 '22 08:10

headinabook