リモートPCをシャットダウンする@WMI
WMIを使ってリモートPCをシャットダウンさせるスクリプト。
objOperatingSystem.Win32Shutdown(REBOOT)
を変更する事で再起動やログオフも可能です。また、実行には対象PCに対する管理者権限が必要です。なお、動作確認はWindows XP SP2でのみです。
Function ShutDownWindows(strComputer)
' On error resume NextConst LogOff = 0 'ログオフ
Const REBOOT = 2 '再起動
Const SHUTDOWN = 8 'シャットダウン
Dim objWMIService
Dim colOperatingSystems
Dim objOperatingSystemSet objWMIService = GetObject("winmgmts:{impersonationLevel= impersonate,(Shutdown)}\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(REBOOT)
Next
End Function
呼び出し方
Call ShutDownWindows("PC名")
Popularity: 2%
トラックバック URI : http://pnpk.net/cms/archives/407/trackback/
【関連記事】