当一个单独的进程关闭时,关闭进程 [英] Close process when a separate process closes
问题描述
因此,在启动特定程序(c:\ Program.exe)之后,我使用任务计划程序运行特定文件(c:\ Newfile.exe).
So I use task scheduler to run a specific file (c:\Newfile.exe) after a specific program has been started (c:\Program.exe).
我想知道当"Program.exe"关闭时如何关闭"Newfile.exe".我知道这无法使用任务计划程序完成,有人知道实现此方案结果的方法吗?
I'd like to know how I can close "Newfile.exe" when "Program.exe" closes. I know this can't be done with task scheduler, does anyone know of a way to achieve this scenario outcome?
亲切的问候
使用任务计划程序尝试
推荐答案
该程序运行,等待程序退出,检查是否为Notepad.exe,是否终止MyProgram.exe.终止程序后,使用 Exit Do
退出脚本.
This program runs waiting for a program to exit, checks if it was Notepad.exe and if so terminates MyProgram.exe. Use an Exit Do
after terminating your program to also quit the script.
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
这篇关于当一个单独的进程关闭时,关闭进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!