one addition to the accepted answer: it is important to redirect the output and output of PsExec call errors (it took 2 days of debugging). See http://jenkins.361315.n4.nabble.com/remotely-executing-commands-td3476417.html
it seems that if a call from java (e.g. jenkins / tomcat) or .net PsExec hangs or fails. so the call should look like this:
c:\someBatchWithPsExec.bat >>log.txt>&1
or explicitly with each call:
PsExec.exe -u [domain \ remoteuser] -p [password] / accepteula \ remoteMachine net [stop | start] Tomcat7 → log.txt> & 1
I think if jenkins works with the \ user u domain, no need to mention this in the command ?! (just tried, but it didn’t work - network commands do not work)
source share