DWORD FindProcess(CString strProcessName)
{
DWORD aProcesses[1024], cbNeeded, cbMNeeded;
HMODULE hMods[1024];
HANDLE hProcess;
wchar_t szProcessName[MAX_PATH];
CString ProcessName;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 0;
for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++)
{
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]);
EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbMNeeded);
GetModuleFileNameEx( hProcess, hMods[0], szProcessName,sizeof(szProcessName));
CString strCur(szProcessName);
if(strProcessName.GetLength()>strCur.GetLength())
continue;
if(strProcessName == strCur.Right(strProcessName.GetLength()))
{
return(aProcesses[i]);
}
}
return 0;
}
记得加上头文件#include <Psapi.h>
引用对应库文件:Psapi.Lib
浙公网安备 33010602011771号