获得64位进程完整路径

时间:2012-07-12 06:30:54

标签: c++ windows

我的代码只获得32位进程的完整路径,我想得到32和64。 我也试过QueryFullProcessImageName

   HANDLE ProcessSnap;
PROCESSENTRY32 Pe32;
unsigned int LoopCounter = 0;

Pe32.dwSize = sizeof(PROCESSENTRY32);
ProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

Process32First(ProcessSnap, &Pe32);

do
{
    HANDLE Process;
    wchar_t FilePath[MAX_PATH];

    Process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, Pe32.th32ProcessID);

    if (Process)
    {
        GetModuleFileNameEx(Process, 0, FilePath, MAX_PATH);
        wprintf(L"%s \n", FilePath);
        CloseHandle(Process);
    }

    LoopCounter++;
} while (Process32Next(ProcessSnap, &Pe32));

CloseHandle(ProcessSnap);

OpenProcess为64位进程返回null。还删除了错误处理以提高可读性。

0 个答案:

没有答案