QT_获取运行进程所在目录路径_1

QString getProcessPathForWin(int idProcess)
{
#ifdef Q_OS_WIN
    // access process path
    WCHAR name[1024];
    ZeroMemory(name, 1024);
    // open process handler
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, idProcess);
    if (NULL != hProcess)
    {
        DWORD cbNeeded;
        HMODULE hMod;
        // process path
        if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
        {
            DWORD dw = GetModuleFileNameExW(hProcess, hMod, name, 1024);
        }
        CloseHandle(hProcess);
    }
    return QString::fromWCharArray(name);
#else
    return "";
#endif
}

 

posted @ 2018-10-12 10:39  风来风往风伤(TiAmo)  阅读(1640)  评论(0编辑  收藏  举报