3

I want to run a script I called "systemInfo.vbs" that outputs to a logfile the system name and service pack.

In command prompt I am doing "PsExec.exe \REMOTECOMPUTER -c systemInfo.vbs".

I am running this from a directory on my local system that has ONLY PsExec.exe and systemInfo.vbs

I get the error

PsExec could not start systemInfo.vbs on REMOTESERVER: "The system cannot find the file specified.

Any idea why this may be? I thought I could do this to run a remote script as if it is on the remote server?

Envin
  • 1,463
  • 8
  • 32
  • 69

2 Answers2

3

You need to give the path to your script either on the remote pc or through a UNC path on a share on your pc or a netsworkdrive. So if the script has a copy on the remote c:\

PsExec.exe \\REMOTECOMPUTER -c c:\systemInfo.vbs

or if it is on the share \\mypc\shared

PsExec.exe \\REMOTECOMPUTER -c \\mypc\shared\systemInfo.vbs

Also you need to make sure you have administrator rights on the pc where you start the script and depending on what your script does possibly on the remote pc as well.

peter
  • 41,770
  • 5
  • 64
  • 108
  • I thought with -c, it would copy the script over and execute it on the remote system? – Envin Jul 17 '12 at 18:04
  • never used that option and in case of trouble i would surely omit it and try it like i suggested, your error message clearly indicates there's a problem with that option but first try giving the full path to the script on your local system, since psexec is executed with administrative rights it could be it loses the context – peter Jul 17 '12 at 20:12
0

For anyone who might encounter this in the future, the -c flag does allow you to copy over a file for execution; the documentation didn't specify, but you need to follow it with the path on your local machine to the binary you want copied and executed. (I have submitted a pull request to the documentation.)

For example, this could be used to add the "Blend for Visual Studio SDK for .NET" to a remote installation of Visual Studio 2017 Professional by copying the web installer (named vs_professional.exe) to that machine (\\TargetMachine) with credentials, (note the DOMAIN is only if you're using a domain instead of local user), and executing it with appropriate parameters.

D:\PSTools\PsExec64.exe "\\TargetMachine" -u "DOMAIN\user" -p "pass" -h -c "D:\deploy\vs_professional.exe" vs_professional.exe modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional" --add Microsoft.Component.Blend.SDK.WPF --passive

Another contrived example:

PsExec64.exe \\Target -u user -p password -h -c "filetoremoteexec.exe" filetoremoteexec.exe --flag param1 param2
CodeShane
  • 6,480
  • 1
  • 18
  • 24