Prozesse auflisten
-
Hi @all,
hab ein sch*** problem und kann den fehler absolut nicht finden.
GetModuleFileNameW bringt einen fehler und GetLastError sagt: Fail with error 0, successfully, na toll!Hier mal der code:
void CreateProcessInfo( HANDLE hProcess ) { CStdStringW strProcessPath; DWORD dwPriorClass = 0; if( GetModuleFileNameW( (HMODULE)hProcess, strProcessPath.GetBuffer( 1000 ), 999 ) == 0 ) // <-- Das hier schlägt fehl { #ifdef MYDBG MessageBoxA( NULL, "Fehler GetModuleFileNameW : CreateProcessInfo", "Fehler", MB_OK ); #endif CloseHandle( hProcess ); return; } MessageBoxW( NULL, strProcessPath, L"Jep Pfad", MB_OK ); return; } void EnumProcess( void ) { HANDLE hProcessSnapshot = NULL; HANDLE hProcess = NULL; PROCESSENTRY32 pc32; hProcessSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnapshot == INVALID_HANDLE_VALUE ) { #ifdef MYDBG MessageBoxA( NULL, "Fehler CreateToolhelp32Snapshot : EnumProcesses", "Fehler", MB_OK ); #endif return; } pc32.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hProcessSnapshot,&pc32)) { do { hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pc32.th32ProcessID ); if( hProcess == NULL ) continue; CreateProcessInfo( hProcess ); CloseHandle( hProcess ); } while(Process32Next(hProcessSnapshot,&pc32)); } CloseHandle(hProcessSnapshot); return; }Hoffe ihr könnt den fehler finden.
gruß
maierps. dieses smilie gefällt mir ganz besonders :schland:

-
GetModuleFileName funktioniert doch nur für den eigenen Prozess. Das sieht man doch schon daran das der ein HMODULE nimmt.
-
Verwende "GetModuleFileNameEx"!
-
Hab ihr da auch ne lösung die auch auf win9x systemen funktioniert?
Und wo könnte ich eine gute (offline) winapi dokumentation bekommen? bei meiner ist getfilenameex nicht mal drinnen!
gruß
kurzschluss
-
Und wo könnte ich eine gute (offline) winapi dokumentation bekommen?
Platform SDK. Ist aber ein paar hundert MB groß.
-
Der Name der Exe Datei steht doch sowieso schon in szExeFile der PROCESSENTRY32 Struktur

MfG,
:schland: *Ranner* :schland:
-
Ranner schrieb:
Der Name der Exe Datei steht doch sowieso schon in szExeFile der PROCESSENTRY32 Struktur

Eben. Nur der Name. Vermutlich geht es ihm um den Pfad.
-
kurzschluss schrieb:
Und wo könnte ich eine gute (offline) winapi dokumentation bekommen? bei meiner ist getfilenameex nicht mal drinnen!
Die Doku bekomst Du, wenn Du das PSDK installierst oder VS kaufst...
-
@*Ranner*
Genau ich hätte gerne den gfad zum prozessDas PSDK und VC8 werde ich mir noch runterladen, aber erst wenn ich eine flatrate hab

Aber es muss doch wohl auch unter Win9x, ME eine möglichkeit geben die laufenden prozesse aufzulisten???
gruß
kurzschluss
-
BOOL ListProcessModules( DWORD dwPID ) { HANDLE hModuleSnap = INVALID_HANDLE_VALUE; MODULEENTRY32 me32; // Take a snapshot of all modules in the specified process. hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID ); if( hModuleSnap == INVALID_HANDLE_VALUE ) { printError( "CreateToolhelp32Snapshot (of modules)" ); return( FALSE ); } // Set the size of the structure before using it. me32.dwSize = sizeof( MODULEENTRY32 ); // Retrieve information about the first module, // and exit if unsuccessful if( !Module32First( hModuleSnap, &me32 ) ) { printError( "Module32First" ); // Show cause of failure CloseHandle( hModuleSnap ); // Must clean up the snapshot object! return( FALSE ); } // Now walk the module list of the process, // and display information about each module do { printf( "\n\n MODULE NAME: %s", me32.szModule ); printf( "\n executable = %s", me32.szExePath ); printf( "\n process ID = 0x%08X", me32.th32ProcessID ); printf( "\n ref count (g) = 0x%04X", me32.GlblcntUsage ); printf( "\n ref count (p) = 0x%04X", me32.ProccntUsage ); printf( "\n base address = 0x%08X", (DWORD) me32.modBaseAddr ); printf( "\n base size = %d", me32.modBaseSize ); } while( Module32Next( hModuleSnap, &me32 ) ); CloseHandle( hModuleSnap ); return( TRUE ); }MfG,
:schland: *Ranner* :schland:
-
danke für die mühe, ich möchte aber alle prozesse auflisten und dann den exe-pfad herausbekommen.
Unter windows nt und höher funktioniert das ja schon alles, aber die psapi.dll funktioniert nicht unter win9x und winme.gruß
kurzschluss
-
Ah merke gerade wie du das gemeint hast. zuerst liste ich alle prozesse auf für die ich dann
einzelnt die module aufliste und dann den pfad der exe herausbekomme!Danke vielmals

gruß
kurzschlussohne holland fahrn wir nach berlin :schland:
