代码之家  ›  专栏  ›  技术社区  ›  Matthew Lock fge

无法用自动热键关闭某些进程

  •  2
  • Matthew Lock fge  · 技术社区  · 15 年前

    我在创建一个小型自动热键脚本以结束测试服务器上的所有vsjitdebugger.exe进程时遇到问题。这是我的代码:

    Process, Exist, vsjitdebugger.exe
    NewPID = %ErrorLevel%
    if NewPID = 0
    {
        MsgBox Process doesnt exist
    }
    else
    {
        MsgBox Process exists
    }
    
    
    Process, WaitClose, vsjitdebugger.exe, 5
    NewPID = %ErrorLevel%
    if NewPID = 0
    {
        MsgBox Process no longer exists
    }
    else
    {
        MsgBox Process still exists
    }
    

    当运行时,脚本告诉我(vsjitdebugger.exe)进程存在,正如我所期望的那样,但是当waitclose发生时,它仍然告诉我进程存在,当我在任务管理器中查找相同数量的vsjitdebugger.exe进程时,它仍在运行。

    我可以使用任务管理器手动结束vsjitdebugger.exe进程。

    基本上,我无法结束这些过程。有人能帮我吗?谢谢。

    更新 :我也尝试过这个简单的循环,但没有用:

    Loop, 100
    {
        Process, Close, vsjitdebugger.exe
    }
    

    更新2 :我尝试了下面建议的代码,但它始终保持在循环中,没有进程被终止:

    Loop
    {
        Process, Close, vsjitdebugger.exe
        Process, wait, vsjitdebugger.exe, 0.1             
        NewPID = %ErrorLevel%
        if NewPID = 0
        {
            break
        }   
    }
    
    3 回复  |  直到 11 年前
        1
  •  2
  •   Agent_9191    15 年前

    假设您的系统上有taskkill.exe(我知道Windows XP有,我相信之后的所有版本也有),您可以使用以下行:

    Run, %comspec% /c "taskkill /F /IM vsjitdebugger /T"
    
        2
  •  3
  •   the3seashells    15 年前

    我的计算机上没有安装Microsoft Visual Studio,因此无法使用确切的过程进行测试。我用notepad.exe代替。使用您发布的简单循环,我成功地关闭了10个记事本实例。

    以下代码在我的计算机(winxp sp3)上工作,以关闭notepad.exe的所有实例。

    Process, Exist, notepad.exe
    NewPID = %ErrorLevel%
    if NewPID = 0
    {
        MsgBox, Process doesnt exist
    }
    else
    {
        MsgBox, Process exists
    }
    
    Loop
    {
        Process, Close, Notepad.exe
        Process, wait, Notepad.exe, 0.1     
        NewPID = %ErrorLevel%
        if NewPID = 0
        {
            break
        }   
    }
    Process, WaitClose, Notepad.exe
    MsgBox, this works
    

    我不确定这是否是造成这些问题的原因,但是 等待关闭 命令不关闭进程,它只等待进程不再存在。

        3
  •  1
  •   Korrigan    14 年前

    我刚升级到Windows7,发现无法关闭进程也有同样的问题。对我有用的是在xp兼容模式下运行程序。