'Win32_OperatingSystem object の Win32ShutDown method を使ってWindowsの終了、ログオフ、再起動、電源オフを行います。 ' 'システムの実行特権を与えるための数値 ' wbemPrivilegeLocal = 18 ' wbemPrivilegeRemote = 23 '動作と値の対応 ' ログオフ : Log Off = 0 ' Windowsの終了 : Shutdown = 1 ' 再起動 : Reboot = 2 ' 電源オフ : Power Off = 8 ' 強制ログオフ : Forced Log Off = 0 + 4 = 4 ' Windowsの強制終了 : Forced Shutdown = 1 + 4 = 5 ' 強制終了と再起動 : Forced Reboot = 2 + 4 = 6 ' 強制終了と電源オフ : Forced Power Off = 8 + 4 = 12 Const wbemPrivilegeLocal = 18 Const wbemPrivilegeRemote = 23 Const LogOff = 0 Const Shutdown = 1 Const Reboot = 2 Const PowerOff = 8 Const ForcedLogOff = 4 Const ForcedShutdown = 5 Const ForcedReboot = 6 Const ForcedPowerOff = 12 Dim Connection, WQL, SystemClass, System, toDo 'ここで終了動作を選択できます。 'toDo = LogOff 'toDo = ForcedLogOff 'toDo = Shutdown 'toDo = ForcedShutdown toDo = Reboot 'toDo = ForcedReboot 'toDo = PowerOff 'toDo = ForcedPowerOff '自マシン上の 「wmi」 に接続 Set Connection = GetObject("winmgmts:root\cimv2") '自マシン上でシステムの実行特権を許可する Set Security = Connection.Security_ Security.Privileges.Add wbemPrivilegeLocal 'Get Win32_OperatingSystem objects - このコレクションは1つのオブジェクトのみ WQL = "Select Name From Win32_OperatingSystem" Set SystemClass = Connection.ExecQuery(WQL, , 0) 'システムオブジェクトを取り出してシャットダウン処理 For Each System In SystemClass System.Win32ShutDown (toDo) Next