<pre name="code" class="cpp">int CSoftware::FindProcess(char *strProcessName)
{
DWORD dwProcess[1024], cbNeeded, cbMNeeded;
HMODULE hModuls[1024];
HANDLE hProcess;
char szProcessName[MAX_PATH];
int i;
if (!EnumProcesses(dwProcess, sizeof(dwProcess), &cbNeeded))
{
return -1;
}
for (i=0; i< (int)(cbNeeded/sizeof(DWORD)); i++)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcess[i]);
if (hProcess == NULL)
{
continue;
}
if (!EnumProcessModules(hProcess, hModuls, sizeof(hModuls), &cbMNeeded))
{
continue;
}
if (!GetModuleFileNameEx(hProcess, hModuls[0], szProcessName,sizeof(szProcessName)))
{
continue;
}
if (strstr(szProcessName, strProcessName))
{
return(dwProcess[i]);
}
}
return -1;
}
FindProcess (vc++ 改进版 )
最新推荐文章于 2022-03-01 10:16:27 发布