2

I want to run a CSharp process from my java server under a different user. I use PSExec to do this - it works fine on my PC, but when doing it on a "real" server, the process immediately crashes. (It seems that the CSharp app does not even start - i tried to print something to a file as the first command, but nothing was written).

Both the user that run the java process and the other user are in the Administrator group.

I have no idea why the application crashes.

This is my code:

ProcessBuilder processBuilder = new ProcessBuilder(
 "c:\\pstools\\PsExec.exe",
 "-u",
 "username",
 "-p",
 "password",
 appPath,
 arg1,
 arg2);

processBuilder.start();
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141
  • Does the PSExec still work with the C# app on the "real" server, even if Java is not involved (if you run it manually)? If so, you'll probably need to post your code and commands here for review... – ziesemer Dec 30 '11 at 15:46
  • yes, it works. i use ProcessBuilder to run the command. I am sure the code is OK – Erik Sapir Dec 30 '11 at 16:08
  • Well, clearly something isn't right. Please post your code, and then we'll have something to work off of. – ziesemer Dec 30 '11 at 17:36
  • 1
    Quotes don't balance, \'s need to be doubled ... is this really the code? – bmargulies Dec 30 '11 at 17:41
  • This is not the exact code. I use consants and i don't want to write the name of the app i try to rum or its arguments – Erik Sapir Dec 30 '11 at 17:52

3 Answers3

1

try with XCmd by Zoltan Csizmadia : http://feldkir.ch/xcmd.htm

This problem has been discussed on sysinternals forum and as I remeber there was a problem with EOL symbol that psexec uses.

You'll have no problems with xcmd

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • I tried but could not understand how i should use it. It asks to enter a computer name and i don't understand what i should use – Erik Sapir Dec 30 '11 at 17:49
  • almost the same way as psexec: xCmd.exe \\computer /user:somebody /pwd:* /d:d:\ test1.exe where "computer" is the name of the remote computer. – npocmaka Dec 30 '11 at 19:33
  • What if i use the same computer? i want to run on localhost. I recieve the following message every time: the system cannot find the file specified. my command is: xCmd.exe \\ cmd – Erik Sapir Dec 30 '11 at 20:16
  • Could you check if xCmdSvc service is running? (This service is installed by xcmd on the remote system) Did you run the command as administrator? You can try to delete the service with "sc delete xCmdSvc" and retry , but I'm not sure I can help if service failed to start - may be you can check event logs for more information. – npocmaka Dec 30 '11 at 23:29
  • and could you check also if your machine has ADMIN$ share? – npocmaka Dec 30 '11 at 23:36
0

My virus scanner doesn't allow xcmd.

However paexec is a drop-in replacement for psexec that also works perfectly.

http://www.poweradmin.com/PAExec/

Tom
  • 55,743
  • 3
  • 27
  • 35
0

It works just fine. Remember that you need to have double \\ in your ShellCommandString. My coworker just came to me with this question, i googoled it and got to this page.. processBuilder will work just fine, make sure the stirng you have is = the stirng you wish to have in cmd

ProcessBuilder processBuilder = new ProcessBuilder(
    "Psexec \\\\\\\\10.192.246.76 -i -u Administrator -p admin2193 cmd /c C:\\\\CI\\\\AutoTest\\\\agent_test1.bat");

processBuilder.start();
kapex
  • 28,903
  • 6
  • 107
  • 121
Gino
  • 317
  • 2
  • 18