The script runs a Microsoft tool called psexec which I use to connect to a
remote Cisco CallManager server running Windows 2000 Server. It then runs a
command called mmfspy.exe with an argument, in this case i. The results of
'mmfspy i' is redirected to a text file on my Windows 2000 Pro workstation.
If I just open a command prompt on my workstation and run 'C:\PsTools\psexec
\\192.168.160.129 -u ccmpub\administrator -p cisco mmfspy i>c:\test.txt' ,
everything works fine.
When I try to call the same command using a vbscrip on my workstation,
everything runs BUT the text file is not created. The piping is not working
when run inside a script. I can not figure out how to make this pipe command
work. Can anyone correct my code and show me what I am doing wrong?
My Complete Code:
Dim objNetwork
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator
-p cisco mmfspy i>c:\test.txt"
It depends on the folder context in which your script is running. I
would assume that it would output the file in the folder your script is
running in, but I don't use this syntax normally, and couldn't tell you
for sure.
What I would recommend doing is the following:
Rather than using the WshShell Run method, I would suggest calling the
Exec method. This is well-documented on MSDN, and gives you direct
access to the StdIn, StdOut, and StdErr streams. When you call the Exec
method, you will be returned a WshShellExec object, which contains
several properties pointing to the respective streams. These properties
each return a stream object that allows you to read or write to the
stream. Actually, I just found a great article on it here:
http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1002.mspx
-----------------------------------------------------------------
Also, just so you're aware, since you're new to scripting, and although
I would NOT recommend using it for this particular case, you can use WMI
to spawn a process. The Win32_Process class beneath the root\cimv2
namespace has a "Create" method that takes a string parameter, which
would contain the command you want to run. This is really handy for when
you want to spawn a process on a system remotely, but I don't believe
that it gives you access to any of the I/O streams that you need for
this scenario.
Hope this helps,
-----------------
Trevor Sullivan
Systems Engineer
objShell.Run "C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator
-p cisco mmfspy i>c:\test.txt"
to
objShell.Run "%comspec% /C C:\PsTools\psexec \\192.168.160.129 -u ccmpub\administrator
----------------
Trevor Sullivan
Systems Engineer