单独进程关闭时关闭进程

问题描述 投票:-1回答:1

所以我使用任务调度程序在特定程序启动后运行特定文件(c:\ Newfile.exe)(c:\ Program.exe)。

我想知道当“Program.exe”关闭时如何关闭“Newfile.exe”。我知道使用任务调度程序无法做到这一点,是否有人知道实现此方案结果的方法?

亲切的问候

尝试使用任务调度程序

batch-file process task scheduler
1个回答
0
投票

此程序运行等待程序退出,检查它是否是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
© www.soinside.com 2019 - 2024. All rights reserved.