首页 > 解决方案 > 如何使用自动热键获取进程的目录?

问题描述

我想找出一个进程的目录。目前,我正在使用此脚本来检查进程是否正在运行:

If ProcessExist("MEmuHeadless.exe")
    MsgBox MEmuHeadless.exe exists.

If !ProcessExist("MEmuHeadless.exe")
    MsgBox Ofcourse it doesn't exist.

ProcessExist(Name){
    Process,Exist,%Name%
    return Errorlevel
}

但更重要的是,我想检查进程的目录是否与此匹配:

在此处输入图像描述

我怎样才能在自动热键中做到这一点?

标签: processautohotkey

解决方案


我为你找到了这个解决方案。看来您必须搜索一些 com 对象才能获取有关该过程的额外信息。

Msgbox % GetProcessPath( "Autohotkey.exe" )
ExitApp
GetProcessPath(exe) {
    for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where name ='" exe "'")
        return process.ExecutablePath
}

推荐阅读