... PROCESSENTRY32 pe32 = {0}; ... pe32.szExeFile //ici ...
HMODULE hModule=(HMODULE)pe32.th32ParentProcessID; szPath[256]=""; GetModuleFileName(hModule,szPath,sizeof(szPath));
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <windows.h> #include <tlhelp32.h> #include <stdio.h> BOOL GetProcessModule (DWORD dwPID, DWORD dwModuleID, LPMODULEENTRY32 lpMe32, DWORD cbMe32) { BOOL bRet = FALSE; BOOL bFound = FALSE; HANDLE hModuleSnap = NULL; MODULEENTRY32 me32 = {0}; // Take a snapshot of all modules in the specified process. hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID); if (hModuleSnap == (HANDLE)-1) return (FALSE); // Fill the size of the structure before using it. me32.dwSize = sizeof(MODULEENTRY32); // Walk the module list of the process, and find the module of // interest. Then copy the information to the buffer pointed // to by lpMe32 so that it can be returned to the caller. if (Module32First(hModuleSnap, &me32)) { do { if (me32.th32ModuleID == dwModuleID) { CopyMemory (lpMe32, &me32, cbMe32); bFound = TRUE; } } while (!bFound && Module32Next(hModuleSnap, &me32)); bRet = bFound; // if this sets bRet to FALSE, dwModuleID // no longer exists in specified process } else bRet = FALSE; // could not walk module list // Do not forget to clean up the snapshot object. CloseHandle (hModuleSnap); return (bRet); } BOOL GetProcessList () { HANDLE hProcessSnap = NULL; BOOL bRet = FALSE; PROCESSENTRY32 pe32 = {0}; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == (HANDLE)-1) return (FALSE); // Fill in the size of the structure before using it. pe32.dwSize = sizeof(PROCESSENTRY32); // Walk the snapshot of the processes, and for each process, // display information. if (Process32First(hProcessSnap, &pe32)) { DWORD dwPriorityClass; BOOL bGotModule = FALSE; MODULEENTRY32 me32 = {0}; do { bGotModule = GetProcessModule(pe32.th32ProcessID, pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32)); if (bGotModule) { HANDLE hProcess; // Get the actual priority class. hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID); dwPriorityClass = GetPriorityClass (hProcess); CloseHandle (hProcess); // Print the process's information. printf( "\nPriority Class Base\t%d\n", pe32.pcPriClassBase); printf( "PID\t\t\t%d\n", pe32.th32ProcessID); printf( "Thread Count\t\t%d\n", pe32.cntThreads); printf( "Module Name\t\t%s\n", me32.szModule); printf( "Full Path\t\t%s\n\n", me32.szExePath); } } while (Process32Next(hProcessSnap, &pe32)); bRet = TRUE; } else bRet = FALSE; // could not walk the list of processes // Do not forget to clean up the snapshot object. CloseHandle (hProcessSnap); return (bRet); } void main(void) { GetProcessList(); }
--------------------Configuration: ProcessInfo - Win32 Debug-------------------- Compiling resources... Compiling... ProcessInfo.cpp You are not using the latest Platform SDK header/library files. This may prevent the project from building correctly. c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\cmnhdr.h(212) : error C2065: 'GetWindowLongPtr' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\cmnhdr.h(212) : error C2065: 'GWLP_HINSTANCE' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(16) : error C2061: syntax error : identifier 'PCTSTR' c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(19) : error C2065: 'pszFormat' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(42) : error C2065: 'PCTSTR' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(42) : error C2146: syntax error : missing ';' before identifier 'pszExeFile' c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(42) : error C2065: 'pszExeFile' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(42) : error C2440: '=' : cannot convert from 'char *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(43) : error C2440: '=' : cannot convert from 'char [260]' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(148) : error C2660: 'AddText' : function does not take 3 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(153) : error C2660: 'AddText' : function does not take 7 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(165) : error C2660: 'AddText' : function does not take 7 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(172) : error C2660: 'AddText' : function does not take 2 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(174) : error C2660: 'AddText' : function does not take 3 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(181) : error C2660: 'AddText' : function does not take 7 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(184) : error C2660: 'AddText' : function does not take 6 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(191) : error C2660: 'AddText' : function does not take 2 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(202) : error C2660: 'AddText' : function does not take 4 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(211) : error C2061: syntax error : identifier 'PCTSTR' c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(218) : error C2065: 'pszModulePath' : undeclared identifier c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(219) : error C2660: 'AddText' : function does not take 2 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(220) : error C2660: 'AddText' : function does not take 2 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(228) : error C2660: 'AddText' : function does not take 5 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(314) : error C2660: 'ShowModuleInfo' : function does not take 2 parameters c:\documents and settings\domino\mes documents\mes fichiers reçus\processinfo\processinfo.cpp(360) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struc t HWND__ *,unsigned int,unsigned int,long)' None of the functions with this name in scope match the target type Error executing cl.exe. ProcessInfo.exe - 25 error(s), 0 warning(s)