关闭特定程序后,是否可以运行.cmd文件? [英] Is there a way to run a .cmd file when a specific program is closed?

查看:86
本文介绍了关闭特定程序后,是否可以运行.cmd文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在关闭Netflix时关闭程序GOPHER.exe。我已经设置好了,这样当我打开Netflix时,GOPHER也将打开。现在,.cmd文件中用于关闭GOPHER的命令是 TASKKILL / IM gopher.exe。我希望它在关闭Netflix时运行。

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.

推荐答案

此程序监视使用WMI(MS的WBEM实现)退出的程序。

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

这篇关于关闭特定程序后,是否可以运行.cmd文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆