'*--------------------------------------------------------------------------------------- '* Windows Vista & Windows Server 2008用 OSシャットダウン実行スクリプト '* '* Windows Vista または Widnwos Server 2008にてOSシャットダウンを実行する場合は '* このスクリプトをタスクスケジューラに登録することによって、USBカードでも入力異常時に '* 休止状態以外で安全なOSシャットダウンが実行可能です。 '* '*--------------------------------------------------------------------------------------- On Error Resume Next strComputer = "." stopcounter = 0 Availability = 0 BatteryStatus = 0 EstimatedChargeRemaining = 0 Set colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent") Do stopcounter = 0 Set strLatestEvent = colMonitoredEvents.NextEvent '* イベントの取得 Do Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery",,48) For Each objItem in colItems Availability = objItem.Availability BatteryStatus = objItem.BatteryStatus EstimatedChargeRemaining = objItem.EstimatedChargeRemaining Next Wscript.Sleep(1000) If Availability = 3 then if BatteryStatus = 1 and EstimatedChargeRemaining = 0 and stopcounter < 10 Then stopcounter = stopcounter + 1 if stopcounter >= 10 then '* --------------------------------------------------------------------------------------------------------- '* ここにOSシャットダウン実行時の処理を記述する 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(1) '* Shutdown '* ObjOperatingSystem.Win32Shutdown(5) '* Forced Shutdown '* ObjOperatingSystem.Win32Shutdown(8) '* Power Off ObjOperatingSystem.Win32Shutdown(12) '* Forced Power Off Next '* --------------------------------------------------------------------------------------------------------- end if end if Else Exit Do '* バッテリ駆動時以外はイベント取得へ戻る End If Loop Loop