aktive Prozesse anzeigen
-
hi!
wie kann ich einsehen welche prozesse gerade aktiv sind (wie im win taskmanager angezeigt)? welche methoden gibts dafür...hab in der suche nix gefunden...
thx
-
Kein Wunder ist auch ein Betriebssysemabhängiges Verfahren... Wenn du mir jetzt sagst, welches OS du nutzt, dann kann ich dich passend verschieben. (Ich vermute mal du benutzt Windows?)
-junix
-
jo sry... natürlich windows
-
-
mhm... das Bsp. funktioniert irgendwie nicht...
-
Was funktioniert denn nicht?
Du musst den Code natürlich noch in eine Konsoneanwendung kopieren und in main die Funktion aufrufen
-
haha ja das ist mir schon klar
nee hab beide funktionen GetProcessList() und GetProcessModule() im code drin...
wenn ich GetProcessList aufrufe gibt er allerdings kein ergebnis aus...
-
Was sagt denn GetLastError() ?
Übrigens funktioniert das ganze nicht mit NT4.0.
-
Für NT 4 braucht man die Funktionen der PSAPI.dll. Wenn man also das Prozesse-raussuchen wirklich 100% komtpatibel haben will, dann muss man wohl oder übel alle dazu benötigten Funktionen dynamisch einbinden. Ich glaube die Funktionen der PSAPI.dll hießen: EnumProcesses und EnumProcessModules. Das erste von EnumProcessModules zurückgegebene Modul ist das Hauptmodul (also die EXE). Den Namen bekommt man dann via GetModuleBaseName (ebenfalls PSAPI.dll).
-
#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 == INVALID_HANDLE_VALUE) 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 == INVALID_HANDLE_VALUE) 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); } int main(int argc, char* argv[]) { GetProcessList(); getchar(); return 0; }
kriege ne leere konsolenbox raus... was hab ich falsch gemacht?
-
das würde mich auchmal interessieren
-
Die Namen der Exe-Datei bekommst du schon, wenn du den "if(bGotModule)" Block in GetProcessList und den GetProcessModule-Aufruf weglässt und einfach direkt pe32.szExeName (oder so ähnlich) ausgibst.
Aber warum funktioniert GetProcessModule nicht? Das würde mich auch interessieren, ich habe das Bsp. nämlich auch letztens 1:1 aus dem Platform-SDK kopiert und es hat nicht funktioniert...
-
Seltsamerweise findet man keine Infos zu GetProcessModule() in der MSDN. Nur 2 Beispiele, wie man es verwendet...
Vielleicht funktioniert GetProcessModule nur unter XP (W2K, NT)?
Welches Betriebssystem verwendet ihr denn?
-
me verwendet XP
-
Ich auch.
Aber ich hab auch noch windows 98 zum Testen.Seltsamerweise findet man keine Infos zu GetProcessModule() in der MSDN. Nur 2 Beispiele, wie man es verwendet...
GetProcessModule ist ja das Beispiel, keine Funktion der WinAPI. Logisch, dass es dazu kaum Infos gibt.
edit:
Ich habs noch nicht unter win98 getestet. Mach ich bald mal.[ Dieser Beitrag wurde am 30.04.2003 um 14:36 Uhr von cd9000 editiert. ]
-
Original erstellt von cd9000:
**GetProcessModule ist ja das Beispiel, keine Funktion der WinAPI. Logisch, dass es dazu kaum Infos gibt.
**Autsch. Naja, ich hab die Beispiele auch nur kurz überflogen...
Ich meine aber ich hatte mal ein "Alle-Prozesse-Auflistung"-Beispiel aus der MSDN getestet und das lief... ich such mal in meinen Test-Projekten...
-
Wenn ihr den Dateinamen sehen wollte, dann lasst euch anzeigen: pe32.szExeFile
-
Warum hast du diesen alten Thread wieder hochgeholt?
Zumal ich genau das schon weiter oben vorgeschlagen hatte...