有没有办法在特定程序关闭时运行.cmd文件?

时间:2018-02-25 01:11:17

标签: batch-file cmd command command-prompt

我想在关闭Netflix时关闭程序GOPHER.exe。我已经设置好了,当我打开Netflix时,GOPHER也会打开。现在,关闭GOPHER的.cmd文件中的命令是“TASKKILL / IM gopher.exe”。我想在关闭Netflix时运行它。

1 个答案:

答案 0 :(得分:0)

它监视使用WMI退出的程序(MS的WBEM实现)。在这里它检查记事本是否退出并重新启动它。

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