4

I have a batch file named a.bat on a winserver2008 Desktop.

That batch file only write the SessionID (from environment variable) to a local eventlog.

I want to execute it remotely using cmd (otherwise the SessionName doesn't appear).

so I have tried

c:\PsTools\psexec.exe \\<Server> -u test2 -p <Password> -i 2 cmd "c:\Users\test-2\Desktop\a"

or

c:\PsTools\psexec.exe \\<server> -u test2 -p <Password> -i 2 "cmd \"c:\Users\test-2\Desktop\a\"";exit

all of these just open a terminal on the remote machine but don't execute the batch.

Any ides?

Best Regards,

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

5

Use a /c on the command line after cmd.

So, your first line would look like:

c:\PsTools\psexec.exe \\<Server> -u test2 -p <Password> -i 2 cmd /c "c:\Users\test-2\Desktop\a"
Michael Todd
  • 16,679
  • 4
  • 49
  • 69
  • I'll try that out though my problem wasn't terminating the remote process but executng this command specific via cmd (and not "directly"). – Elad Benda May 07 '10 at 10:22
0

psexec \\<server> -s cmd.exe & whatever.bat

If you're trying to run a batch remotely then when cmd is open on the remote through your terminal connection, you have two options:

  1. xcopy \\your_computer\filepath c:\wherever something.bat
  2. run \\computername\c$\wherever_it_is_located
joce
  • 9,624
  • 19
  • 56
  • 74
kai
  • 1