判断指定进程名的进程是否存在
时间:2010-05-28 来源:w1_xiao
DWORD GetProcessidFromName(LPCTSTR name)
{
PROCESSENTRY32 pe;
DWORD id=0;
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe.dwSize=sizeof(PROCESSENTRY32);
if(!Process32First(hSnapshot,&pe))
return 0;
while(1)
{
pe.dwSize=sizeof(PROCESSENTRY32);
if(Process32Next(hSnapshot,&pe)==FALSE)
break;
if(strcmp(pe.szExeFile,name)==0)
{
id=pe.th32ProcessID;
break;
}
}
CloseHandle(hSnapshot);
return id;
}
相关阅读 更多 +