スキャン完了後にシャットダウンする
以上のようなことをふまえて作成したのがこちら↓
Option Explicit Call StartScan If WaitForEndScan Then Call Shutdown End If ' ウィルススキャンを実行する Sub StartScan Dim WShell Set WShell = WScript.CreateObject("WScript.Shell") WShell.CurrentDirectory = "D:\Download\vpscan\" Call WShell.Run("vpscan.exe /ini",,True) End Sub ' ウィルススキャンの終了まで待機する Function WaitForEndScan Dim objWMIService Dim colMonitoredEvents Dim objLatestEvent Set objWMIService = _ GetObject("winmgmts:{impersonationLevel=impersonate, (Security)}!\\.\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from __instancecreationevent where TargetInstance isa 'Win32_NTLogEvent' " _ & "and (TargetInstance.EventCode = '2' OR TargetInstance.EventCode = '21')") Set objLatestEvent = colMonitoredEvents.NextEvent ' EventCode=2:スキャン完了 ' EventCode=21:スキャンキャンセル If objLatestEvent.TargetInstance.EventCode = 2 Then WaitForEndScan = True Else WaitForEndScan = False End If End Function ' シャットダウン Sub Shutdown Const LogOff = 0 'ログオフ Const ForcedLogOff = 4 '強制ログオフ 0 + 4 Const Shutdown = 1 'シャットダウン Const ForcedShutdown = 5 '強制シャットダウン 1 + 4 Const Reboot = 2 '再起動 Const ForcedReboot = 6 '強制再起動 2 + 4 Const PowerOff = 8 '電源断 Const ForcedPowerOff = 12 '強制電源断 8 + 4 Dim colOperatingSystems Dim objOperatingSystem Set colOperatingSystems = _ GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems Call ObjOperatingSystem.Win32Shutdown(PowerOff) Next End Sub
これでスキャンが完了した時点で、シャットダウンが実行される。
また、スキャンをキャンセルした場合は、何もしない。