如何让 .bat 文件在弹出警告框时自动运行?

如何让 .bat 文件在弹出警告框时自动运行?

有时候我的电脑上的 POP Peeper 突然无法运行。每次发生这种情况时,都会弹出一个警告框,任务管理器中该框的 PID 为 244。解决方法是重新启动 POP Peeper。我知道如何使用 .bat 文件来重新启动程序,但不知道如何让该文件在弹出警告框时自动运行。

有人能教我怎么做吗?
以下是有问题的警报框。 在此处输入图片描述

答案1

下面的脚本应该可以完成你想要的操作关闭弹出窗口然后重新启动另一个进程

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    i = x 
    Do While i = x
        Set colProcesses = objWMIService.ExecQuery _
            ("Select * from Win32_Process Where Name = 'notepad.exe'")
            '("Select * from Win32_Process Where Name = 'Name of Your process you are waiting for to start'")

    If colProcesses.Count = 0 Then
        'It does not exist do nothing
    Else
        For Each objProcess in colProcesses
            'this will close the process you were watching, as soon as it starts
            objProcess.Terminate()

                'Closing the process you want to restart
                Set colProcesses = objWMIService.ExecQuery _
                 ("SELECT * FROM Win32_Process WHERE Name = 'winword.exe'")
                 '("SELECT * FROM Win32_Process WHERE Name = 'name of the process you want to terminate'")
                For Each objProcess2 in colProcesses
                 objProcess2.Terminate()
                Next

            Dim objShell
            Set objShell = WScript.CreateObject( "WScript.Shell" )

            objShell.Run("""C:\Program Files (x86)\Internet Explorer\iexplore.exe""")
            'objShell.Run("""process or application you want to start""")
            Set objShell = Nothing

        Next
    End If

Loop

相关内容