2008/5/1 木曜日

リモートPCをシャットダウンする@WMI

Filed under: Windows XP, スクリプト — pnpk @ 15:45:25

WMIを使ってリモートPCをシャットダウンさせるスクリプト。

objOperatingSystem.Win32Shutdown(REBOOT)

を変更する事で再起動やログオフも可能です。また、実行には対象PCに対する管理者権限が必要です。なお、動作確認はWindows XP SP2でのみです。

Function ShutDownWindows(strComputer)
'    On error resume Next

    Const LogOff   = 0 'ログオフ
    Const REBOOT   = 2 '再起動
    Const SHUTDOWN = 8 'シャットダウン
    
    Dim objWMIService
    Dim colOperatingSystems
    Dim objOperatingSystem

    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(REBOOT)
    Next
End Function

呼び出し方

Call ShutDownWindows("PC名")

Popularity: 2%

コメント (0) »

この記事にはまだコメントがついていません。

コメント RSS トラックバック URI

コメントをどうぞ

HTML convert time: 0.497 sec. Powered by WordPress ME