2009年1月3日 星期六

自動重開機

一般情況要自動重開機很簡單,很多小工具可以達成,但是若server的桌面是在"鎖定"的狀態下,直接排程重開機的指令是沒有作用的喔,最好的方好是先排程"登出"的指令,然後再排程"重開機"的指令囉

1.將下列script存成logoff.vbs ,這是登出用的
On Error Resume Next

Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
Const LOGOFF = 0
Const SHUTDOWN = 1
Const REBOOT = 2
Const FORCE = 4
Const POWEROFF = 8
'登出
For Each objPC In GetObject("winmgmts:{(shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
objPC.Win32Shutdown LOGOFF + FORCE
Next

2.將下列script存成restart.vbs,這是重開機用
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

3. 將下列script存成logoff.bat
::先強制登出以解除鎖定
cscript logoff.vbs

4.將下列script存成restart.bat::解除鎖定後才能重開機
cscript restart.vbs

5.先排程logoff.bat,間隔幾分鐘再排程restart.bat就可以輕鬆實現自動重開機囉

0 意見:

張貼留言