#include
#include
int getpid(char *name)
{
HANDLE hprocessSnap = NULL;
PROCESSENTRY32 pe32 ={0};
hprocessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hprocessSnap ==(HANDLE)-1) {
printf("\nCreateToolhelp32Snapshot()failed:%d",GetLastError());
return 1;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hprocessSnap,&pe32)){
do {
printf("\n%-20s%d",pe32.szExeFile,pe32.th32ProcessID);
if (!strcmp(name, pe32.szExeFile))
return (int)pe32.th32ProcessID;
}while (Process32Next(hprocessSnap,&pe32));
}
else
printf("\nProcess32Firstt() failed:%d",GetLastError());
CloseHandle (hprocessSnap);
return 0;
}
阅读(551) | 评论(0) | 转发(0) |