版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Giser_D/article/details/91567369
//判断进程id是否存在
//@param:process_id:需要传入的进程id值
//return:True:存在,False:不存在
BOOL isExistProcess(DWORD process_id)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hSnapshot) {
return NULL;
}
PROCESSENTRY32 pe = { sizeof(pe) };
for (BOOL ret = Process32First(hSnapshot, &pe); ret; ret = Process32Next(hSnapshot, &pe)) {
if (pe.th32ProcessID == process_id)
{
return TRUE;
}
}
CloseHandle(hSnapshot);
return FALSE;
}