Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with WshShell.Run, WaitOnReturn

Status
Not open for further replies.

bmquiroz

IS-IT--Management
Sep 26, 2003
207
US
Hello all,

Need help with the below code. I want to run defrag.exe from within a script then have the script pause until defrag.exe finishes, it should then resume execution. Problem is that defrag.exe spawns dfrgntfs.exe, how do I pass this to the script? It's not pausing!

Thanks for the help!

Sip

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "defrag.exe c: -a",True

strComputer = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
 
Have you tried this ?
WshShell.run "defrag.exe c: -a",[highlight],[/highlight]True

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the quick reply! I added the extra comma and it worked! Also made the reboot process into a function.

Sip

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "defrag.exe c: ",,True

Reboot

Function Reboot
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top