Hauptprogramm mit Unterprogramme beenden?

partitionist

Erfahrenes Mitglied
Hallo, ich stehe vor einem Problem, wenn eine Anwendung XYZ eine andere Anwendung startet z.B. hallo.exe, wie kann man diese dann mit dem Hautprogramm beenden?

Bei dem Process Explorer von Sysinternals gibt es zwei Funktionen zum beenden:

Kill Process
Kill Process Tree

Wenn ich die Anwendung XYZ mit Kill Process Tree beende, so wird auch hallo.exe beendet, das möchte ich nun auch realisieren habe hierfür folgenden Code der nur ein Prozess schließt, was muss geändert werden das auch Unterprogramme beendet werden?

Code:
 BOOL KillProcessByName(char *szProcessToKill) 
{ 
        HANDLE hProcessSnap; 
        HANDLE hProcess; 
        PROCESSENTRY32 pe32; 
        //DWORD dwPriorityClass; 
 
        hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); 
 
    if( hProcessSnap == INVALID_HANDLE_VALUE ) 
    { 
        printError( "CreateToolhelp32Snapshot (of processes)" ); 
        return( FALSE ); 
    } 
 
    pe32.dwSize = sizeof( PROCESSENTRY32 ); 
 
    if( !Process32First( hProcessSnap, &pe32 ) ) 
    { 
        printError( "Process32First" ); 
        CloseHandle( hProcessSnap ); 
        return( FALSE ); 
    } 
 
    do 
    { 
        if(!strcmp(pe32.szExeFile,szProcessToKill)) 
        { 
            //printf("Prozess: %s \n",pe32.szExeFile); 
            //printf("PID: %d \n",pe32.th32ProcessID ); 
            textcolor(red); 
            cout << "killed ["; 
            textcolor(light); 
            cout << pe32.szExeFile; 
            textcolor(red); 
            cout << "]"; 
            textcolor(grey);             
            cout << "PID: " << pe32.th32ProcessID << endl; 
 
            hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID); 
            TerminateProcess(hProcess,0); 
            CloseHandle(hProcess); 
        } 
    } while( Process32Next(hProcessSnap,&pe32) ); 
 
 
    CloseHandle( hProcessSnap ); 
        return( TRUE ); 
}
 
Zurück