我寫了一個自動關機的排程
Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(8)
Next
但是遇到一個問題...
如果在開機之後,期間如果有人遠端桌面連線登入或是登入再登出...
系統就會跳出仍有人登入,將windows關機可能導到他們的資料遺失,您要繼續關機嗎?
可是這是設定在晚上二點執行,這時候一定沒有人去按"是"...
請問各位邦友要如何解決咧....
這是我曾經寫過的關機程式:
主要的內容是監控 logon.scr 這個螢幕保護是否啟動,一偵測到啟動的話就執行關機的動作,你可以視需求拿掉,程式的最後我有列出關機的參數。
<pre class="c" name="code">
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objEventSource = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 5 where TargetInstance isa 'Win32_Process' and TargetInstance.Name='logon.scr'")
DO
Set objEventObject=objEventSource.NextEvent()
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(5)
'0-> Log Off
'4-> Forced Log Off
'1-> Shutdown
'5-> Forced Shutdown
'2-> Reboot
'6-> Forced Reboot
'8-> Power Off
'12->Forced Power Off
Next
LOOP