0

I am using vbscript to run an exe on a remote system. First i connect to the remote system.

Set objSWbemServices = objSWbemLocator.ConnectServer _
    (strComputer, "root\cimv2", _
    strUser, strPassword)

Then i create a process on the remote system.

Set Process = objSWbemServices.Get("Win32_Process")
result = Process.Create("cmd /C ""cd " & somedir & " && " & "Collector.exe -v", , , intProcessID)

Now this code works fine. However the exe gives some output on the console which i want to redirect to a file on my local system.

I tried the following options

result = Process.Create("cmd &1>abc.txt /C ""cd " & somedir & " && " & "Collector.exe -v", , , intProcessID)

While the above option does not work at all,

or

result = Process.Create("cmd /C ""cd " & somedir & " && " & "Collector.exe -v > abc.txt", , , intProcessID)

this code created the file in the remote system. However i want the file to be created in the local system from where i am running my vbscript. Any help??

ayush
  • 14,350
  • 11
  • 53
  • 100

1 Answers1

1

You could try redirecting the output to a UNC path:

Set net = CreateObject("WScript.Network")

result = Process.Create("cmd /C ""cd " & somedir & " && " _
         & "Collector.exe -v > \\" & net.ComputerName & "\share\abc.txt" _
         , , , intProcessID)

The share must exist on the local computer and the user running the remote process must be granted write access to it.

Untested, though, so I'm not sure it'll work.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328