O R G A N I C / F E R T I L I Z E R: executing batch files remotely with psexec …

Oct 2, 2008

executing batch files remotely with psexec …

if you’ve got a batch file of some sort (bat or cmd) sitting out somewhere that you want to execute remotely, you’ll want to make sure you’re following the right syntax to get this to work.

here are some examples that DO NOT work:

psexec \\myDesktop \\myServer\myShare\test.cmd

 

PsExec could not start \\myServer\myShare\test.cmd on myDesktop:
Access is denied.

 

by default, psexec runs the context in localsystem.  since the system most likely doesn’t have access to the share, let’s give psexec some credentials which has access to the share:

psexec \\myDesktop -u myUser -p myPassword \\myServer\myShare\test.cmd

 

PsExec could not start \\myServer\myShare\test.cmd on myDesktop:
Access is denied.

 

ah, this isn’t going to work either, but we’re getting closer.  the access denied message throws me off a little since i know the password is right.  it seems the problem is that psexec will not execute the .cmd or .bat file without knowing the context in which to execute… so we give it one.  cmd.exe.

psexec \\myDesktop -u myUser -p myPassword cmd /c \\myServer\myShare\test.cmd

 

C:\WINDOWS\system32>mkdir c:\testme
cmd exited on myDesktop with error code 0.

 

now there we go… :)