Discussion:
Force reboot using WMI
(too old to reply)
Jeff Giroux
2004-04-14 20:51:32 UTC
Permalink
Is there a way to force a reboot incase the user "locked" the machine with
the below script. I can reboot the machine when logged in or not, but if
the user does CTRL+ALT+DEL and then chooses Lock Computer, then the script
will not reboot the machine. Is there a force command?

strComputer = "remotePC"

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
Michael Holzemer
2004-04-15 04:31:58 UTC
Permalink
In item news:***@tk2msftngp13.phx.gbl,
Jeff Giroux says...
Post by Jeff Giroux
Is there a way to force a reboot incase the user "locked" the machine with
the below script. I can reboot the machine when logged in or not, but if
the user does CTRL+ALT+DEL and then chooses Lock Computer, then the script
will not reboot the machine. Is there a force command?
strComputer = "remotePC"
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
Here are the flags for win32shutdown

'// Computer logoff/shutdown script
'// Flags
'// 0 Log Off
'// 0 + 4 Forced Log Off
'// 1 Shutdown
'// 1 + 4 Forced Shutdown
'// 2 Reboot
'// 2 + 4 Forced Reboot
'// 8 Power Off
'// 8 + 4 Forced Power Off

Instead of this
ObjOperatingSystem.Reboot()

Use
ObjOperatingSystem.Win32Shutdown(6)
The 6 represents 2 + 4 for forced reboot

You will also need the remote shutdown privilege
& "{impersonationLevel=impersonate,(Shutdown, RemoteShutdown)}!\\" & strComputer
&
--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/community/scriptcenter/default.mspx
Slim
2004-04-15 14:08:28 UTC
Permalink
Post by Jeff Giroux
Is there a way to force a reboot incase the user "locked" the machine with
the below script. I can reboot the machine when logged in or not, but if
the user does CTRL+ALT+DEL and then chooses Lock Computer, then the script
will not reboot the machine. Is there a force command?
strComputer = "remotePC"
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
Set Connection =
GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!root\cimv2")

wql = "Select Name From Win32_OperatingSystem"
Set SystemClass = Connection.ExecQuery(wql)



For Each System In SystemClass


System.Win32ShutDown (2)

System.Win32ShutDown (4)

Next

Continue reading on narkive:
Loading...