WScript.Shell and execution blocking?

I use WScript to automate some tasks using WScript.Shell to call external programs.

However, now he does not wait for the completion of the external program and instead switches. This causes problems because I have some tasks depending on others completing first.

I use code like:

ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir Set wshShell = WScript.CreateObject("Wscript.Shell") wshShell.run ZipCommand 

Is there any way to do this so that it locks until the shell executable returns?

+6
shell vbscript wsh
source share
2 answers

It turns out that while the cycle is heavy CPU hog: P

I found a better way:

 ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir Set wshShell = WScript.CreateObject("Wscript.Shell") wshShell.Run ZipCommand,1,1 

Last two arguments: Show window and block execution :)

+13
source share

If you use the Exec method, it returns a link, so you can poll the Status property to determine when it will complete. Here is an example from msdn :

 Dim WshShell, oExec Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec(ZipCommand) Do While oExec.Status = 0 WScript.Sleep 100 Loop 
+5
source share

All Articles