首页 > 系统相关 >Windows下根据进程id获得进程名

Windows下根据进程id获得进程名

时间:2022-12-29 16:06:27浏览次数:51  
标签:return Windows ret id pe 进程 hSnapshot dwPid


//根据进程id获得进程名
wstring GetModuleName(DWORD dwPid)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,dwPid);
if (INVALID_HANDLE_VALUE == hSnapshot)
{
return L"";
}
PROCESSENTRY32 pe = { sizeof(pe) }; //存放进程快照信息的结构体
BOOL ret = Process32First(hSnapshot,&pe); //获得第一个进程的信息
//遍历
while (ret)
{
if (dwPid == pe.th32ProcessID)
{
CloseHandle(hSnapshot);
return wstring(pe.szExeFile);
}
ret = Process32Next(hSnapshot,&pe); //接着往下遍历
}
}

参数dwPid:进程号,返回值:进程名

标签:return,Windows,ret,id,pe,进程,hSnapshot,dwPid
From: https://blog.51cto.com/u_15906863/5978166

相关文章