// Process Description Information Typedef struct _tagprocessinfo {dWord dwpid; tchar strpath [_max_path]; tchar strname [_max_fname];} processinfo, * lpprocessinfo
// Get Process Information List Bool EnumprocesSinfo (ProcessInfo * LPPSINFO, ULONG ULSIZE, ULONG * Pulneed) // LPPSINFO [OUT]: Pointer to the array of Processinfo Structure // nsize [in]: LPPSINFO Elements in Lppsinfo Number // NNEEDED [ OUT]: The actual element number // Return value: true: success; false: failed {assert (pulneeded); lpdword lpdwpids; // Storage process ID array DWORD DWBSIZE, DWBSIZE2; dwbsize2 = 256 * sizeof (dWord); lpdwpids = NULL;
Do {
IF (LPDWPIDS) {
HeapFree (getProcessHeap (), 0, lpdwpids; dwbsize2 * = 2;}
LPDWPIDS = (LPDWORD) HeapAlloc (getProcessHeap (), 0, dwbsize2); if (lpdwpids == null) {Return False;}
IF (! :: Enumprocesses (LPDWPIDS, DWBSIZE2, & DWBSIZE)) {
HeapFree (getProcessHeap (), 0, lpdwpids; return false;}
} while (dwbsize == dwbsize2);
Ulong ulcount = dwbsize / sizeof (DWORD); // Returns the actual number IF (NULL == LPPSINFO && 0 == ulsize) {* pulneeded;}
Assert (lppsinfo); if (null == lppsinfo) {Return False;}
IF (ulsize <= ulcount) {* pulneeded = ulsize;} else {* pulneed = ulcount;
// Get the process information Handle HProcess; HModule HModule; DWORD DWSIZE;
char path_buffer [_MAX_PATH]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char fname [_MAX_FNAME]; char ext [_MAX_EXT]; // Loop through each ProcID for (ULONG ulIndex = 0;. ulIndex <(* pulNeeded) Ulindex ) {// Open the process (if we can ... security does not // permit every process in the system) .// Trace ("PID to open:% D", LPDWPIDS [ULINDEX]);
LPPSINFO [ULINDEX] .dwpid = lpdwpids [ulindex]; lppsinfo [ulindex] .strPath [0] = 0; lpsinfo [ulindex] .strname [0] = 0; // Because can't open 0 and 8 process, // Mark the at there f (0 == lpdwpids [ulindex]) {structure (lppsinfo [ulindex] .strname, "system idle process"); Continue;} else if (8 == lpdwpids [ulIndex]) {
STRCPY (LPPSINFO [Ulindex] .strName, "System"); Continue;}
// Open Process And Get Process Infomation hProcess = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, lpPsInfo [ulIndex] .dwPID); if (! HProcess = NULL) {// Here we call EnumProcessModules to get only the // first module in the process this is important, // because this will be the .EXE module for which we // will retrieve the full path name in a second. if (EnumProcessModules (hProcess, & hModule, sizeof (hModule), & dwSize)) {
// Get Full pathname: if (GetModuleFileNameEx (hProcess, hModule, path_buffer, sizeof (path_buffer))) {_tsplitpath (path_buffer, drive, dir, fname, ext); strcpy (lpPsInfo [ulIndex] .strPath, path_buffer); sprintf ( LPPSINFO [ULINDEX] .STRNAME, "% S% S", FNAME, EXT); // Trace ("ModuleFileName:% S", Path_buffer;}}}}}}}
Reference:
(Http://www.9cbs.net/expert/topic/580/580874.xml?temp=.7492029)
I would like to thank you!
Return True;}