列举进程

xp:

#include <windows.h>
#include <tlhelp32.h>

int SearchProess(const char* name)
{
int ret=0;
HANDLE handle=NULL;
PROCESSENTRY32 pe32={0};
do
{
handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(handle==(HANDLE)-1)break;
pe32.dwSize=sizeof(PROCESSENTRY32);
if(!Process32First(handle,&pe32))break;
do
{
if(strcmp(pe32.szExeFile,name)==0)
{
ret=1;
break;
}
}
while(Process32Next(handle,&pe32));
} while (0);
if(handle)
{
CloseHandle(handle);
handle=NULL;
}
return ret;
}

WINCE:

#include <tlhelp32.h>
#pragma comment(lib, "Toolhelp.lib ")


int SearchProess(const TCHAR* name)
{
int ret=0;
HANDLE handle=NULL;
PROCESSENTRY32 pe32={0};
do
{
handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(handle==(HANDLE)-1)break;
pe32.dwSize=sizeof(PROCESSENTRY32);
if(!Process32First(handle,&pe32))break;
do
{
if(_tcscmp(pe32.szExeFile,name)==0)
{
ret=1;
break;
}
}
while(Process32Next(handle,&pe32));
} while (0);
if(handle)
{
CloseToolhelp32Snapshot(handle);
handle=NULL;
}
return ret;
}

原文地址:https://www.cnblogs.com/ccmfc/p/2624635.html