1

I have an issue trying to execute a batch file using Psexec.
For testing purposes, i have an batch file located at the remote server. The batch file will just do an hello world Echo HelloWorld pause.

When i try to execute the batch file using Psexec, it says that my batchfile was successfully started. But When i go into my server it wasn't. I have run the Batch file physically and it works fine. Wondering what exactly had happened.

I have tried using Psexec to shutdown my server. It works but batch file don't!

Appreciate if experts out there could tell me why! Thanks!

Friday
  • 11
  • 1
    What psexec command are you using to launch the batch file? – Josh Sep 11 '13 at 04:52
  • Hi, the command i ran is psexec \10.10.10.32 -u "admin" -p "password" -i -d c:\users\admin\desktop\batchfile\helloworld.bat When i took away the -d i realise that psexec got stuck while running the batch file. It just hangs there. – Friday Sep 11 '13 at 09:20
  • I have also tried the -accepteula command, and it doesn't work too. – Friday Sep 11 '13 at 09:27
  • No errors was return. It just stop at calling the batch file and it doesn't exit. while at my remote server, nothing was invoked – Friday Sep 11 '13 at 09:28
  • Check if the psexecsvc service is still running on the remote host. If so, then stop and delete it using SC command. Also, did you verify your creds were entered correctly and you have admin access? I suggest leaving in the accepteula, but change - to / – Lizz Sep 11 '13 at 13:30
  • Try launching the batch file with cmd /c c:\users\admin\desktop\batchfile\helloworld.bat – Josh Sep 11 '13 at 14:51
  • Hi Lizz I have tried your method but it didn't work, and yes the creds were correct with admin access. – Friday Sep 12 '13 at 02:20
  • Hi josh, with ur command given, yes the batch file was execute properly – Friday Sep 12 '13 at 02:22
  • I did some test on my side, and i realize what was causing the issue. WHEN i remove the -i from the psexec command it didn't hang. But now whatever command i typed on the batch file will not be execute on my remote server. it's just printing out the output of my bat file. I do really need the -i function. – Friday Sep 12 '13 at 02:25

1 Answers1

1
psexec -i 2 -d \\Server -u Domain\Username -p Password c:\Path\to\file.bat

I'm afraid I'm not entirely sure why this works, but having come across this yesterday, this was my solution - the "-i 2", presumably, changing the sort of interaction psexec has with the remote machine. Otherwise, cmd will run as a background process.

Kev
  • 11
  • 1