How to force restart a Windows box using VBScript?

Posted by tloach on Stack Overflow See other posts from Stack Overflow or by tloach
Published on 2008-10-09T18:43:58Z Indexed on 2010/03/26 8:23 UTC
Read the original article Hit count: 273

Filed under:
|
|

I'm trying to find a way to force Windows to reboot, and I am running into issues. I've tried

Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _
     & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_
     & "Primary=true")
for each OpSys in OpSysSet
    retVal = OpSys.Reboot()
next

I've also tried using the shutdown -f -r command, and in both cases I sometimes get no response, and if I try again I get an error saying "Action could not complete because the system is shutting down" even though no matter how long I leave it it doesn't shut down, it still allows me to start new programs, and doing a shutdown -a gives the same error. How can a script be used to force Windows to reboot?

© Stack Overflow or respective owner

Related posts about vbscript

Related posts about Windows