Allan Cady
2004-12-03 21:10:14 UTC
Why would a process that runs to completion when run directly or from
a DOS batch file, fail to finish when run using WshShell.Exec?
I'm trying to run a VPN client program from VBScript, using the
WshShell.Exec command:
Set exec = wsh.Exec("vpnclient connect MyServer")
Do While (exec.Status = WshRunning)
WScript.Sleep 100
Loop
I need a way to test whether the connection was successful. When
running the client from a batch file, this can be done by testing
ERRORLEVEL. For example, a batch file containing this:
vpnclient connect MyServer
ECHO Command returned ERRORLEVEL: %ERRORLEVEL%
exits after a couple of seconds, and echoes "200" if the connection is
successful.
Presumably, I should be able to access this exit code from VBScript
using the ExitCode property of the exec object. The problem is, when
I run the script, exec.Status never changes from WshRunning (0).
According to the MS documentation, "If the process has not finished,
the ExitCode property returns 0", so I can never check the exit code.
Can anyone suggest why the Exec never finishes, and if there might be
some workaround?
Thanks,
Allan
a DOS batch file, fail to finish when run using WshShell.Exec?
I'm trying to run a VPN client program from VBScript, using the
WshShell.Exec command:
Set exec = wsh.Exec("vpnclient connect MyServer")
Do While (exec.Status = WshRunning)
WScript.Sleep 100
Loop
I need a way to test whether the connection was successful. When
running the client from a batch file, this can be done by testing
ERRORLEVEL. For example, a batch file containing this:
vpnclient connect MyServer
ECHO Command returned ERRORLEVEL: %ERRORLEVEL%
exits after a couple of seconds, and echoes "200" if the connection is
successful.
Presumably, I should be able to access this exit code from VBScript
using the ExitCode property of the exec object. The problem is, when
I run the script, exec.Status never changes from WshRunning (0).
According to the MS documentation, "If the process has not finished,
the ExitCode property returns 0", so I can never check the exit code.
Can anyone suggest why the Exec never finishes, and if there might be
some workaround?
Thanks,
Allan