c++ 使用PID获取可执行文件路径

#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <Psapi.h>

using namespace std;

int main()
{
	HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 7632);
	char lpFilename[1024];
	GetModuleFileNameExA(hProcess, NULL, (LPSTR)lpFilename, 1024);
	printf("%s\n", lpFilename); //C:\Users\ajanuw\Desktop\game2.exe 
	CloseHandle(hProcess);
	return 0;
}
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 7632);
    char lpFilename[1024];
    size_t lpdwSize = sizeof(lpFilename);
    QueryFullProcessImageNameA(hProcess, 0, lpFilename, (PDWORD)&lpdwSize);
    cout << lpFilename << endl;
    CloseHandle(hProcess);
posted @ 2020-08-30 11:21  Ajanuw  阅读(546)  评论(0编辑  收藏  举报