When VB Script executes a command line program it opens a new window. This can be especially inconvenient when you want to incorporate an external application into your script.
There is a way to have your script keep the console application within the same window, and wait for it to complete.
What we will do is launch the process, and then forward all of the console output of the script. When the process has terminated we exit the loop.
Here is a function that you can drop into your script (Click here to download)
Function ExecuteShellProgram(ByVal sFileName)
Set poShell = CreateObject("WScript.Shell")
Set poProcess = poShell.Exec(sFileName)
'Check to see if we started the process without error
if ((poProcess.ProcessID=0) and (poProcess.Status=1)) then
Err.Raise vbObjectError,,"Failed executing process"
'Now loop until the process has terminated, and pull out
'any console output
'Get current state of the process
iStatus = poProcess.Status
'Forward console output from launched process
'Did the process terminate?
if (iStatus <> 0) then
'Return the exit code
ExecuteShellProgram = poProcess.ExitCode
Here is a simple example. I am going to call the command interpreter, and do listing of the windows folder:
ExecuteShellProgram "%COMSPEC% /c dir c:\windows"
(%COMSPEC% is a system variable that is set to the full path and file name of the command interpreter cmd.exe)
Now you can execute your console helper applications - and use the output in your script.