Die aktuellen Prozesse sehen



  • Hi , ich moechte ein C++ Programm schreiben welched die aktuell laufenden Prozesse in eine Listbox ausgibt. Welche Funktionen ( oder Klassen ) brauche ich ?



  • Hi PhoeNix_FasT, 😉

    Dazu brauchst du: CreateToolhelp32Snapshot - MSDN

    Und Hier hassu n Beispiel.



  • Hey danke , hab das ganze mal auf die Prozessnamen abgespeckt und das kam heraus

    #include <windows.h>
    #include <tlhelp32.h>
    #include <stdio.h>
    
    void main( )
    {
      HANDLE hProcessSnap;
      PROCESSENTRY32 pe32;
    
      hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    
      pe32.dwSize = sizeof( PROCESSENTRY32 );
    
      do
      {
        printf( "\n%s", pe32.szExeFile );
    
      } while( Process32Next( hProcessSnap, &pe32 ) );
    
      CloseHandle( hProcessSnap );
    }
    

    2 Fragen hier :

    Frage (1) Wenn ich den Teil

    do
      {
        printf( "\n%s", pe32.szExeFile );
    
      } while( Process32Next( hProcessSnap, &pe32 ) );
    

    in

    while( Process32Next( hProcessSnap, &pe32 ) );
      {
        printf( "\n%s", pe32.szExeFile );
      }
    

    aendere bekomme ich nur einen Prozess heraus

    Frage (2) :

    Bei der funktionierenden Version bekomme ich das hier :

    http://img209.imageshack.us/img209/7106/aasp2.jpg

    Woran kann das liegen ?



  • Initialisiere die Struktur mal mit ZeroMemory.



  • weiss jetzt nich genau ob du das meinst aber

    #include <windows.h>
    #include <tlhelp32.h>
    #include <stdio.h>
    
    void main( )
    {
      HANDLE hProcessSnap;
      PROCESSENTRY32 pe32;
    
      hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    
      pe32.dwSize = sizeof( PROCESSENTRY32 );
    
      ZeroMemory( &pe32, sizeof(pe32));
    
      do
      {	 
        printf( "\nProzess :  [ %s ]", pe32.szExeFile );
    
      } while( Process32Next( hProcessSnap, &pe32 ) );
    
      CloseHandle( hProcessSnap );
      Sleep(2000);
    }
    

    krieg ich gar nix



  • Hab' da was rumliegen:

    void view_processes( )
    {
        void *snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    
        if( snapshot == INVALID_HANDLE_VALUE ) {
    
            cout << "Couldn't create a snapshot of processes currently running:" << endl;
            cout << get_errmsg( GetLastError( ) ) << endl << endl;
            return;
        }
    
        PROCESSENTRY32 proc_entry;
        proc_entry.dwSize = sizeof( PROCESSENTRY32 );
    
        if( !Process32First( snapshot, &proc_entry ) ) {
    
            unsigned long last_error = GetLastError( );
    
            if( last_error == ERROR_NO_MORE_FILES ) {
    
                cout << "No processes are currently running." << endl;
                cout << "This should not be true in any case!?" << endl << endl;
    
            } else {
    
                cout << "An error occured while trying to enumerate processes currently running:" << endl;
                cout << get_errmsg( last_error ) << endl << endl;
            }
    
            CloseHandle( snapshot );
            return;
        }
    
        do {
            cout << "0x";
            cout.width( 6 );
            cout.fill( '0' );
            cout << hex << proc_entry.th32ProcessID;
            cout << " : " << proc_entry.szExeFile << endl;
    
        } while( Process32Next( snapshot, &proc_entry ) );
    
        unsigned long last_error = GetLastError( );
    
        if( last_error != ERROR_NO_MORE_FILES ) {
    
            cout << "An error occured while trying to enumerate processes currently running:" << endl;
            cout << get_errmsg( last_error ) << endl << endl;
            CloseHandle( snapshot );
            return;
        }
    
        CloseHandle( snapshot );
    }
    

    Greetz, Swordfish


Anmelden zum Antworten