# How do I run programs in background from within VBS script?



## lotuseclat79 (Sep 12, 2003)

Assume the following vbs script called test.vbs below.
testpgm1.exe runs and exits, which allows testpgm2.exe to startup
testpgm2.exe starts up, but never exits which is ok, but this prevents testpgm3.exe and the other executables following it from starting up.

How do I run testpgm2.exe so that it will start up in the background which allows the following executables to startup also, and each in turn runs in the background and also does not exit?

Solution would act like Unix shell script code, like this where '&' puts testpgm2.exe into the background instead of running in the foreground as in testpgm1.exe, and thus allows all following programs to execute:
testpgm1.exe
testpgm2.exe &
...

Tia,

-- Tom

test.vbs script contents after this line:-------------------------------------
Dim WSHShell 
Set WSHShell=Wscript.CreateObject("Wscript.Shell")
WSHShell.Run "C:\testpgm1.exe"
WSHShell.Run "C:\testpgm2.exe"
WSHShell.Run "C:\testpgm3.exe"
WSHShell.Run "C:\testpgm4.exe"
WSHShell.Run "C:\testpgm5.exe"
WSHShell.Run "C:\testpgm6.exe"


----------



## coderitr (Oct 12, 2003)

Using the basic Shell( ) function allows a program to be started and the original program to continue like a "fire it and forget it" mode. I don't know that much about VBS but from your post it sounds like this is what you want. The Shell( ) function also has an optional second parameter to indicate whether or not you want the Shell'ed application to get the focus, minimized, or hidden altogether.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctShell.asp


----------



## cristobal03 (Aug 5, 2005)

Keep in mind that *Shell* runs programs asynchronously, so if you want to run *testpgm1.exe* first before running the others, you'd want to continue to use the *WSHShell* object.

[edit]
I mean, keep using *WSHShell* for the first executable, then *Shell* for all the others.

Sorry 'bout that.
[/edit]

chris.


----------

