void ShowProcName(uint32_t pid)
{
    char tempProcName[MAX_PATH] = { 0 };
    //必须具有的权限
    HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
    if (processHandle == NULL) {
        return;
    }
    auto len = GetModuleBaseNameA(processHandle, NULL, tempProcName, MAX_PATH);
    if (len == 0) {
        printf("Get base namefailed, err: %u", GetLastError());
    }
    printf("%s\n", tempProcName);

    GetModuleFileNameEx(processHandle, NULL, tempProcName, MAX_PATH);
    printf("%s\n", tempProcName);
    
    GetProcessImageFileName(processHandle, tempProcName, MAX_PATH);
    printf("%s\n", tempProcName);

   
    CloseHandle(processHandle);
}

输出:

notepad.exe 
C:\Windows\System32\notepad.exe
\Device\HarddiskVolume3\Windows\System32\notepad.exe

相关文章: