batch-file - 当单独的进程关闭时关闭进程
问题描述
因此,我使用任务调度程序在启动特定程序 (c:\Program.exe) 后运行特定文件 (c:\Newfile.exe)。
我想知道当“Program.exe”关闭时如何关闭“Newfile.exe”。我知道这不能用任务调度程序来完成,有没有人知道实现这种场景结果的方法?
亲切的问候
尝试使用任务调度程序
解决方案
该程序运行等待程序退出,检查它是否是 Notepad.exe,如果是,则终止 MyProgram.exe。Exit Do
在终止程序后使用也退出脚本。
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
If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessName=MyProgram.exe")
For Each itm in ColItems
itm.Terminate
Next
End If
Loop
推荐阅读
- python - Discord py - 对带有冷却时间的消息做出反应(on_message)
- reactjs - 为什么styled-components中的Color模块会报错
- angular - Web3 和 Angular 11 损坏的依赖项
- iframe - 每 5 分钟重复一次自动刷新 IFrame
- c# - 如何使用访问修饰符声明 sqlConnection、sqlCommand、sqlDataAdapter 和 sqlDataReader?
- swift - Swift 中的正则表达式
- haskell - Haskell quickBatch 测试:Applicative Monoid ZipList
- python - 如何从此板图像中删除阴影
- javascript - 我怎样才能最容易地将此 HTTP 响应解析为 JSON,然后访问 responseText 字段?
- postgresql - 如果所选日期 >= 到 current_date,则使用最小日期更新日期字段,除非所有日期都 >= 到当前日期