一、判断指定程序名的进程是否存在
BOOL EnumWindows( WNDENUMPROC lpEnumFunc, // pointer to callback function LPARAM lParam // application-defined value);
The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
BOOL CALLBACK IpEnumFunc(HWND hwnd,LPARAM lParam)
{
char wndName[100];
::GetWindowText(hwnd,wndName,sizeof(wndName));
if(wndName!="")
{
if(strcmp(wndName,name1)==0)
{
WndHnd=hwnd;
flag=1;
}
}
return 1;
}
二、判断指定进程名的进程是否存在
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;
}
如果返回值不为零,则存在,否则不存在。
三/*判断是否是x64进程
参 数:进程句柄
返回值:是x64进程返回TRUE,否则返回FALSE
*/
BOOL IsWow64ProcessEx(HANDLE hProcess)
{
/*判断ntdll中的导出函数,可知是否是64位OS*/
HMODULE hMod=GetModuleHandle("ntdll.dll");
FARPROC x64fun=::GetProcAddress(hMod,"ZwWow64ReadVirtualMemory64");
if(!x64fun) return FALSE;
/*利用IsWow64Process判断是否是x64进程*/
typedef BOOL(WINAPI *pfnIsWow64Process)(HANDLE,PBOOL);
pfnIsWow64Process fnIsWow64Process=NULL;
hMod=GetModuleHandle("kernel32.dll");
fnIsWow64Process=(pfnIsWow64Process)GetProcAddress(hMod,"IsWow64Process");
if(!fnIsWow64Process) return FALSE; //如果没有导出则判定为32位
BOOL bX64;
if(!fnIsWow64Process(hProcess,&bX64)) return FALSE;
return !bX64;
}