I want the program GOPHER.exe to close when I close Netflix. I already have it set so that when I open Netflix, GOPHER also opens. Right now the command in the .cmd file to close GOPHER is "TASKKILL /IM gopher.exe". I want it to run when I close Netflix.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This monitors for programs exiting using WMI (MS's implementation of WBEM). Here it checks for Notepad exiting and restarts it.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM Win32_ProcessStopTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
msgbox objReceivedEvent.ProcessName
If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
WshShell.Run "c:\Windows\notepad.exe", 1, false
End If
Loop