VBS - How do I hide a dos window when running a command

jameswhite1979

Senior member
Apr 15, 2005
367
0
0
Hi guys,

I am using a little bit of code to launch a command and then via a loop wait for it to complete:

------------------------Code Start-----------------------
Dim oWsc, oExec
Set oWsc = CreateObject("WScript.Shell")
Set oExec = oWsc.Exec(""".\AeXAgentUtil.exe"" /Clean")
' wait until finished
Do While oExec.Status <> 1
WScript.Sleep 100
Loop

wscript.echo "Done"

------------------------Code End-----------------------

I understand that via a run command you can add ', 0, True' to the end but this does not appear to be possible when launching it as above.

Is there away using the above code but to hide the DOS window? If not what code could replace this and wait for the command to complete be for continuing?

Thanks J
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
Do you need the object back from the Exec method? Why can't you use Run, which has the wait until return built in?
 

imported_BadKarma

Senior member
Dec 6, 2004
328
0
0
Dont know much about VBS, so I can't guarantee it will work or not.
Probably not the solution you're looking for, but instead of executing "AeXAgentUtil.exe" can you try this instead:

"C:\WINDOWS\system32\cmd.exe /c start "" /d "D:\<PathofAeXagentUtil.exe" "AeXAgentUtil.exe""

 

SearchMaster

Diamond Member
Jun 6, 2002
7,791
114
106
I don't know that you can control the window style on the Exec command.

You can try the Run command instead.

MSDN
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Same as above, use run if you can: the "1" parameter tells it keep minimized/hide I believe.

set ws = wscript.createobject("WScript.shell")
ws.run("ftp.exe -s:data.ftp", 1, false)
 

jameswhite1979

Senior member
Apr 15, 2005
367
0
0
Thanks WannaFly thats great I have to alter the code a little to get it to work:

set ws = wscript.createobject("WScript.shell")
ws.run("notepad.exe"), 0, true


FYI:
0 = Hidden
1 = displayed
True = Waits till command has completed before moving to next
False = Does not wait for command to complete before moving to next