Warum funktioniert break bei der Schleife nicht?
-
#include <windows.h> #include <Tlhelp32.h> #include <iostream> using namespace std; int main() { HANDLE po; PROCESSENTRY32 pe; po = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL); pe.dwSize = sizeof(PROCESSENTRY32); Process32First(po,&pe); for(int i = 0; i < sizeof(pe); ++i) { Process32Next(po,&pe); cout << pe.szExeFile << " "; if(pe.szExeFile == "firefox.exe") break; } cin.sync(); cin.get(); }PS.: firefox.exe läuft bei mir natürlich als Prozess.
sizeof(pe) ist auch falsch, wie bekomme ich die Anzahl der laufenden Prozesse heraus?
-
man strcmp. Die Frage gibt's hier gefühlt täglich...
-
SG1 schrieb:
man strcmp. Die Frage gibt's hier gefühlt täglich...
Passt, danke!

Wie bekomme ich die Anzahl der laufenden Prozesse?
-
Folgende Funktion liefert die Anzahl der laufenden Prozesse zurück:
int GetNumProcesses() { int NumProcesses = 0; HANDLE hSnapshot; PROCESSENTRY32 ProcessEntry; ProcessEntry.dwSize = sizeof(PROCESSENTRY32); hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(Process32First(hSnapshot, &ProcessEntry)) do { NumProcesses++; } while(Process32Next(hSnapshot, &ProcessEntry)); CloseHandle(hSnapshot); return NumProcesses; }MfG, Jochen
-
Jochen S. schrieb:
Folgende Funktion liefert die Anzahl der laufenden Prozesse zurück:
int GetNumProcesses() { int NumProcesses = 0; HANDLE hSnapshot; PROCESSENTRY32 ProcessEntry; ProcessEntry.dwSize = sizeof(PROCESSENTRY32); hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(Process32First(hSnapshot, &ProcessEntry)) do { NumProcesses++; } while(Process32Next(hSnapshot, &ProcessEntry)); CloseHandle(hSnapshot); return NumProcesses; }MfG, Jochen
Dankesehr.