EnumProcesses
-
Hi all, quick question. I've read the MSDN library definition for this API and all i really want to know is can i use it to find a running program or not. Still searhing for a example of this API in use so its still very un-clear to me. Thanx in advance!
-
Hi all, quick question. I've read the MSDN library definition for this API and all i really want to know is can i use it to find a running program or not. Still searhing for a example of this API in use so its still very un-clear to me. Thanx in advance!
EnumProcesses
shows each process on the system but what do you need exactly? -
Hi all, quick question. I've read the MSDN library definition for this API and all i really want to know is can i use it to find a running program or not. Still searhing for a example of this API in use so its still very un-clear to me. Thanx in advance!
DWORD dwPID[16860]; //maximim amount of PIDS possible DWORD dwRet; DWORD dwNumProcesses; if (TRUE == EnumProcesses(dwPID,sizeof(dwPID),&dwRet)) { dwNumProcesses = dwRet / (sizeof(DWORD); for(int i =0;i < dwNumProcesses;++i) { printf(_T("Process ID = %d"),dwPID[i]; } }
Best Wishes, -Randor (David Delaune) -
Hi all, quick question. I've read the MSDN library definition for this API and all i really want to know is can i use it to find a running program or not. Still searhing for a example of this API in use so its still very un-clear to me. Thanx in advance!
This function can check if a process is running by checking the executable name. You may want to add additional checking such as window class enumeration or enumeration of known loaded modules.
BOOL IsExecutableRunning(TCHAR *lpszExe) { HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); PROCESSENTRY32 processInfo; processInfo.dwSize=sizeof(PROCESSENTRY32); while(Process32Next(hSnapShot,&processInfo)!=FALSE) { if(processInfo.th32ProcessID > 12 && _tclen(processInfo.szExeFile) > 0) { if(_tcscmp(processInfo.szExeFile,lpszExe) == 0) { CloseHandle(hSnapShot); return TRUE; } } } CloseHandle(hSnapShot); return FALSE; }
Best Wishes, -Randor (David Delaune)