16,467
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <windows.h>
#include <TlHelp32.h>
int main(int argc, char* argv[])
{
CHAR szImageName[MAX_PATH];
HANDLE hSnapshot;
BOOL bRes;
PROCESSENTRY32 pe = {sizeof(pe)};
scanf("%s", szImageName);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
for (bRes = Process32First(hSnapshot, &pe); bRes; bRes = Process32Next(hSnapshot, &pe))
{
if (!strcmpi(szImageName, pe.szExeFile)) break;
}
if (bRes) printf("%d\n", pe.th32ProcessID);
else printf("Error\n");
return 0;
}