0

I have a C# program that automatically test something on a remote computer. I can run it locally from my development machine, but typically it's ran from build agents on our TeamCity server. The command doesn't do anything other than running a dummy file to confirm the machine is up and running:

PsExec.exe \\10.2.1.216 -u TestUser -p *** -h -accepteula -nobanner -c -f -w C:\ dummy.cmd 

On my machine it works well:

PsExec.exe \\10.2.1.216 -u TestUser -p *** -h -accepteula -nobanner -c -f -w C:\ dummy.cmd 
Connecting to 10.2.1.216...  

Starting PSEXESVC service on 10.2.1.216...

Connecting with PsExec service on 10.2.1.216...

Copying dummy.cmd to 10.2.1.216...

Starting dummy.cmd on 10.2.1.216...

dummy.cmd exited on 10.2.1.216 with error code 0.

On the TC server however, it fails with the very vague "handle is invalid" error:

PsExec.exe \\10.2.1.216 -u TestUser -p *** -h -accepteula -nobanner -c -f -w C:\ dummy.cmd 
The handle is invalid.
Connecting to 10.2.1.216...

Couldn't access 10.2.1.216:

RunCommand process exited with 6
Timst
  • 910
  • 1
  • 11
  • 25
  • Add the code... we still don't have crystall balls to guess what happens. – Gusman Aug 03 '17 at 13:29
  • 1
    The code for what? – Timst Aug 03 '17 at 13:33
  • The code of your program, without seeing how you launch the program we can't know if something is wrong. – Gusman Aug 03 '17 at 13:34
  • Possible duplicate of https://stackoverflow.com/questions/13663167/psexec-the-handle-is-invalid-when-running-the-command-as-system-user – jason.kaisersmith Aug 03 '17 at 13:35
  • 1
    Have you checked access rights? See [this](https://stackoverflow.com/questions/25213606/using-psexec-exe-in-jenkins-handle-is-invalid) (for Jenkins, but might be also your case) or [this](https://superuser.com/questions/200938/psexec-the-handle-is-invalid) – vasek Aug 03 '17 at 13:36
  • I think @Gusman may think psexec is your c# program when it's not. Is that right? – KSib Aug 03 '17 at 13:41
  • I checked those answers yeah. It's a vague error code, so there are a lot of different causes. @gusman: PsExec is ran in my code through a Process with ProcessStartInfo("PsExec.exe", arguments)). The arguments here are "\\10.2.1.216 -u TestUser -p *** -h -accepteula -nobanner -c -f -w C:\ dummy.cmd". – Timst Aug 03 '17 at 13:42
  • The Jenkins issue is the closest to what I'm experiencing, but I can't find any similar settings on TeamCity. – Timst Aug 03 '17 at 13:48
  • 1
    I would forget your C# application for the moment, and on the machine where it doesn't work - manually open a command prompt and run the psexec.exe command. You'll probably find that too errors (meaning it's not your C# app at fault), but is indeed some sort of Windows security permission issue. Get it working through the command prompt first - then when thats working, try your app again. Otherwise look at: https://stackoverflow.com/questions/828432/psexec-access-denied-errors for some other suggestions. – Scott Aug 03 '17 at 14:30
  • @KSib No, is to check how he launches PsExec, to see if he's impersonating an administrator account: https://stackoverflow.com/questions/13663167/psexec-the-handle-is-invalid-when-running-the-command-as-system-user – Gusman Aug 03 '17 at 14:38

0 Answers0