在 VBS 中启动和关闭程序

在 VBS 中启动和关闭程序

我正在使用此脚本启动计算器程序。如何添加行以在 2 分钟后关闭计算器。

Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("SELECT * FROM Win32_PowerManagementEvent")

Do
Set strLatestEvent = colMonitoredEvents.NextEvent
If strLatestEvent.EventType = 4 Then 
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
If objItem.name = "Calculator.exe" then objItem.terminate
Next
ElseIf strLatestEvent.EventType = 7 Then 
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc.exe", 1, false
End If
Loop

相关内容