见如下CheckProcess函数:
用法:
INT nProc = CheckProcess(_T("wininet.dll");
INT CheckProcess(LPCTSTR szFileName)
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
INT nFind = 0;
DWORD dwProcIdThis = GetCurrentProcessId();
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE) {
return FALSE;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof(PROCESSENTRY32);
// Retrieve information about the first process,
// and exit if unsuccessful
if (!Process32First(hProcessSnap, &pe32)) {
CloseHandle(hProcessSnap); // Must clean up the snapshot object!
return FALSE;
}
do {
if (pe32.th32ProcessID == dwProcIdThis) {
continue;
}
if (CheckModules(pe32.th32ProcessID, szFileName)) {
_tprintf_s(_T("%s/n"), pe32.szExeFile);
nFind++;
}
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
return nFind;
}