Psexec, cmd and batch file

I have a batch file named a.bat on the winserver2008 desktop.

This batch file writes only the SessionID (from the environment variable) to the local event log.

I want to execute it remotely using cmd (otherwise the name SessionName will not appear).

so i 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 them simply open the terminal on the remote computer, but do not execute the package.

Any ides?

Regards,

+3
source share
2 answers

Use the / c command on the command line after cmd.

So your first line will look like this:

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

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

, , cmd , :

  • xcopy \\your_computer\filepath c:\wherever something.bat
  • run \\computername\c$\wherever_it_is_located
0

Source: https://habr.com/ru/post/1744186/


All Articles