<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Wie Hauptprogramm mit Unterprogramme schließen?]]></title><description><![CDATA[<p>Hallo ich habe eine Kill Befehl der ein Prozess schließt, doch mir ist aufgefallen das nur dieser beendet wird, also nicht die Unterprogramme (Childprozesse)</p>
<p>Hier mein bisheriger Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;tlhelp32.h&gt;
#include &lt;iostream&gt;
#include &quot;format.h&quot;

using namespace std;

//void printError( TCHAR* msg );
void printError( char* msg );
BOOL KillProcessByName(char *szProcessToKill);

BOOL KillProcessByName(char *szProcessToKill)
{
		HANDLE hProcessSnap;
		HANDLE hProcess;
		PROCESSENTRY32 pe32;
		//DWORD dwPriorityClass;

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	do
	{
		if(!strcmp(pe32.szExeFile,szProcessToKill))
		{
			//printf(&quot;Prozess: %s \n&quot;,pe32.szExeFile);
			//printf(&quot;PID: %d \n&quot;,pe32.th32ProcessID );
			textcolor(red);
			cout &lt;&lt; &quot;killed [&quot;;
			textcolor(light);
			cout &lt;&lt; pe32.szExeFile;
			textcolor(red);
			cout &lt;&lt; &quot;]&quot;;
			textcolor(grey);			
			cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ProcessID &lt;&lt; endl;

			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			TerminateProcess(hProcess,0);
			CloseHandle(hProcess);
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );

	CloseHandle( hProcessSnap );
		return( TRUE );
}

void printError( TCHAR* msg )
{
	DWORD eNum;
	TCHAR sysMsg[256];
	TCHAR* p;

	eNum = GetLastError( );
	FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
	NULL, eNum,
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
	sysMsg, 256, NULL );

	// Trim the end of the line and terminate it with a null
	p = sysMsg;
	while( ( *p &gt; 31 ) || ( *p == 9 ) )
	++p;
	do { *p-- = 0; } while( ( p &gt;= sysMsg ) &amp;&amp;
	( ( *p == '.' ) || ( *p &lt; 33 ) ) );

	// Display the message
	printf( &quot;\n WARNING: %s failed with error %d (%s)&quot;, msg, eNum, sysMsg );
} 

int main(int argc, char* argv[])
{
	if(argc &gt; 1)
	{
		textcolor(grey);
		KillProcessByName(argv[1]);
	}
	else
	{
		textcolor(light);
		cout &lt;&lt; &quot;Verwendung: kill [Prozess]&quot; &lt;&lt; endl &lt;&lt; endl;
		textcolor(yellow);
		cout &lt;&lt; &quot;Beispiel:&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;---------&quot; &lt;&lt; endl;
		textcolor(white);
		cout &lt;&lt; &quot;kill winamp.exe&quot; &lt;&lt; endl;
	}
	return 0;
}
</code></pre>
<p>Was muss am Code geändert werden das noch die Unterprogramme geschloßen werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/185803/wie-hauptprogramm-mit-unterprogramme-schließen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 14:54:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/185803.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Jul 2007 16:02:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Sun, 01 Jul 2007 16:02:40 GMT]]></title><description><![CDATA[<p>Hallo ich habe eine Kill Befehl der ein Prozess schließt, doch mir ist aufgefallen das nur dieser beendet wird, also nicht die Unterprogramme (Childprozesse)</p>
<p>Hier mein bisheriger Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;tlhelp32.h&gt;
#include &lt;iostream&gt;
#include &quot;format.h&quot;

using namespace std;

//void printError( TCHAR* msg );
void printError( char* msg );
BOOL KillProcessByName(char *szProcessToKill);

BOOL KillProcessByName(char *szProcessToKill)
{
		HANDLE hProcessSnap;
		HANDLE hProcess;
		PROCESSENTRY32 pe32;
		//DWORD dwPriorityClass;

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	do
	{
		if(!strcmp(pe32.szExeFile,szProcessToKill))
		{
			//printf(&quot;Prozess: %s \n&quot;,pe32.szExeFile);
			//printf(&quot;PID: %d \n&quot;,pe32.th32ProcessID );
			textcolor(red);
			cout &lt;&lt; &quot;killed [&quot;;
			textcolor(light);
			cout &lt;&lt; pe32.szExeFile;
			textcolor(red);
			cout &lt;&lt; &quot;]&quot;;
			textcolor(grey);			
			cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ProcessID &lt;&lt; endl;

			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			TerminateProcess(hProcess,0);
			CloseHandle(hProcess);
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );

	CloseHandle( hProcessSnap );
		return( TRUE );
}

void printError( TCHAR* msg )
{
	DWORD eNum;
	TCHAR sysMsg[256];
	TCHAR* p;

	eNum = GetLastError( );
	FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
	NULL, eNum,
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
	sysMsg, 256, NULL );

	// Trim the end of the line and terminate it with a null
	p = sysMsg;
	while( ( *p &gt; 31 ) || ( *p == 9 ) )
	++p;
	do { *p-- = 0; } while( ( p &gt;= sysMsg ) &amp;&amp;
	( ( *p == '.' ) || ( *p &lt; 33 ) ) );

	// Display the message
	printf( &quot;\n WARNING: %s failed with error %d (%s)&quot;, msg, eNum, sysMsg );
} 

int main(int argc, char* argv[])
{
	if(argc &gt; 1)
	{
		textcolor(grey);
		KillProcessByName(argv[1]);
	}
	else
	{
		textcolor(light);
		cout &lt;&lt; &quot;Verwendung: kill [Prozess]&quot; &lt;&lt; endl &lt;&lt; endl;
		textcolor(yellow);
		cout &lt;&lt; &quot;Beispiel:&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;---------&quot; &lt;&lt; endl;
		textcolor(white);
		cout &lt;&lt; &quot;kill winamp.exe&quot; &lt;&lt; endl;
	}
	return 0;
}
</code></pre>
<p>Was muss am Code geändert werden das noch die Unterprogramme geschloßen werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1316234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316234</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 01 Jul 2007 16:02:40 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Sun, 01 Jul 2007 17:01:29 GMT]]></title><description><![CDATA[<p>Brauchst eine zweite Process32First / Next - Schleife in der jeder Prozess beendet wird für den gilt : &quot;pr32.th32ParentProcessID == HauptprogrammID&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1316273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316273</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 01 Jul 2007 17:01:29 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Mon, 02 Jul 2007 15:17:05 GMT]]></title><description><![CDATA[<p>Also so wie ich es verstanden habe, muss ich alle Childprozesse beenden wenn diese mit dem hauptprogramm verknüpft sind oder?</p>
<p>Hab hier mal die do-Schleife aus dem Code verändert, aber irgendwie klappt es nicht wahrscheinlich ist die Bedingung falsch:</p>
<pre><code class="language-cpp">do
	{
		if(!strcmp(pe32.szExeFile,szProcessToKill))
		{					
			do
			{
				//Beende hier Childprozesse

			}while(pe32.th32ParentProcessID == pe32.th32ProcessID);

			textcolor(red);
			cout &lt;&lt; &quot;killed [&quot;;
			textcolor(light);
			cout &lt;&lt; pe32.szExeFile;
			textcolor(red);
			cout &lt;&lt; &quot;]&quot;;
			textcolor(grey);			
			cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ProcessID &lt;&lt; endl;

			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			TerminateProcess(hProcess,0);
			CloseHandle(hProcess);
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1316968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316968</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Mon, 02 Jul 2007 15:17:05 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Mon, 02 Jul 2007 17:56:10 GMT]]></title><description><![CDATA[<p>Mit der ersten Schleife suchst Du nur die ID des Hauptprogrammes.<br />
Mit der zweiten Schleife beendest Du alle Programme wo &quot;pe32.th32ParentProcessID == HauptprogrammID&quot; ist.</p>
<pre><code class="language-cpp">DWORD HauptprogrammID;

 CreateToolhelp32Snapshot (...);  // erste Schleife
 Process32First (...); 
 do {
  if(!strcmp(pe32.szExeFile,szProcessToKill)) {
  HauptprogrammID = pe32.th32ProcessID;
  break;
  }
 } while (Process32Next (...));
 CloseHandle (...);

 CreateToolhelp32Snapshot (...);  // zweite Schleife
 Process32First (...);  
 do {
  if (pe32.th32ParentProcessID == HauptprogrammID) {
   // Prozess beenden
  }
 } while (Process32Next (...));
 CloseHandle (...);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1317067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317067</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:56:10 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Tue, 03 Jul 2007 08:21:29 GMT]]></title><description><![CDATA[<p>Habe es nun so gemacht wie du gesagt hast, doch es funktioniert nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Wenn ich die Prozesse ausgebe die geschlossen werden sollen, so werden alle Prozesse aufgelistet?!?!?</p>
<pre><code class="language-cpp">BOOL KillProcessByName(char *szProcessToKill)
{
		DWORD HauptprogrammID;
		HANDLE hProcessSnap;
		HANDLE hProcess;
		PROCESSENTRY32 pe32;
		//DWORD dwPriorityClass;

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	do
	{
		if(!strcmp(pe32.szExeFile,szProcessToKill))
		{
			HauptprogrammID = pe32.th32ProcessID;
			break;
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );
	CloseHandle( hProcessSnap );

	hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	do
	{
		if(pe32.th32ParentProcessID = HauptprogrammID)
		{
			textcolor(red);
			cout &lt;&lt; &quot;killed [&quot;;
			textcolor(light);
			cout &lt;&lt; pe32.szExeFile;
			textcolor(red);
			cout &lt;&lt; &quot;]&quot;;
			textcolor(grey);			
			cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ProcessID &lt;&lt; endl;

			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			TerminateProcess(hProcess,0);
			CloseHandle(hProcess);	
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );
	CloseHandle( hProcessSnap );

	return( TRUE );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1317309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317309</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 03 Jul 2007 08:21:29 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Tue, 03 Jul 2007 14:33:03 GMT]]></title><description><![CDATA[<p>Kann mir jemand bitte weiterhelfen??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317558</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 03 Jul 2007 14:33:03 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Tue, 03 Jul 2007 20:04:06 GMT]]></title><description><![CDATA[<p>kernel64 schrieb:</p>
<blockquote>
<p>Habe es nun so gemacht wie du gesagt hast, ...</p>
</blockquote>
<p>*no comment*</p>
<pre><code class="language-cpp">...
// if(pe32.th32ParentProcessID = HauptprogrammID)
if(pe32.th32ParentProcessID == HauptprogrammID)
...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1317743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317743</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 03 Jul 2007 20:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Tue, 03 Jul 2007 21:06:06 GMT]]></title><description><![CDATA[<blockquote>
<p>// if(pe32.th32ParentProcessID = HauptprogrammID)<br />
if(pe32.th32ParentProcessID == HauptprogrammID)</p>
</blockquote>
<p>Jepp wahr mein Fehler <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Habe meine Funktion so aufgebaut, das man angeben kann ob man ein Prozess mit oder ohne Unterprozesse geschlossen werden soll (<strong>killChildProcess</strong>)</p>
<p>Ich möchte noch eine Änderung vornehmen, wenn mehrere Prozesse z.B. <strong>Hallo.exe</strong> gleichzeitig laufen, dann kann ich diese mit dem Befehl <strong>kill Hallo.exe</strong> alle Prozesse gleichzeitig beenden, doch es funktioniert nicht mit der neuen Funktion.<br />
Nochmal zum Verständnis, alle Prozesse mit dem gleichen Namen <strong>Test.exe</strong> haben Unterprogramme geöffnet, ich möchte nun alle Test.exe mit Unterprogramme schließen wie bei der normalen Methode, was muss man bei der else Teil ändern?</p>
<pre><code class="language-cpp">BOOL KillProcessByName(char *szProcessToKill, bool killChildProcess)
{
		DWORD HauptprogrammID = NULL;
		HANDLE hProcessSnap = NULL;
		HANDLE hProcess = NULL;
		PROCESSENTRY32 pe32;
		//DWORD dwPriorityClass;

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	//Beende einen Prozess
	if(killChildProcess == false)
	{
		do
		{
			if(!strcmp(pe32.szExeFile,szProcessToKill))
			{				
				textcolor(red);
				cout &lt;&lt; &quot;killed [&quot;;
				textcolor(light);
				cout &lt;&lt; pe32.szExeFile;
				textcolor(red);
				cout &lt;&lt; &quot;]&quot;;
				textcolor(grey);           
				cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ProcessID &lt;&lt; endl;

				hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
				TerminateProcess(hProcess,0);
				CloseHandle(hProcess);
			}
		} while( Process32Next(hProcessSnap,&amp;pe32) );

		CloseHandle( hProcessSnap );
        return( TRUE ); 
	}

	//Beende Hauptprozess mit Childprozesse
	else
	{

		do
		{
			if(!strcmp(pe32.szExeFile,szProcessToKill))
			{
				HauptprogrammID = pe32.th32ProcessID;
				break;
			}
		} while( Process32Next(hProcessSnap,&amp;pe32) );
		CloseHandle( hProcessSnap );

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

		if( hProcessSnap == INVALID_HANDLE_VALUE )
		{
			printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
			return( FALSE );
		}

		pe32.dwSize = sizeof( PROCESSENTRY32 );

		if( !Process32First( hProcessSnap, &amp;pe32 ) )
		{
			printError( &quot;Process32First&quot; );
			CloseHandle( hProcessSnap );
			return( FALSE );
		}

		do
		{
			if(pe32.th32ParentProcessID == HauptprogrammID)
			{
				textcolor(red);
				cout &lt;&lt; &quot;killed [&quot;;
				textcolor(light);
				cout &lt;&lt; pe32.szExeFile;
				textcolor(red);
				cout &lt;&lt; &quot;]&quot;;
				textcolor(grey);			
				cout &lt;&lt; &quot;PID: &quot; &lt;&lt; pe32.th32ParentProcessID &lt;&lt; endl;

				hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
				TerminateProcess(hProcess,0);
				CloseHandle(hProcess);	
			}
		} while( Process32Next(hProcessSnap,&amp;pe32) );
		CloseHandle( hProcessSnap );	

		return( TRUE );
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1317772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317772</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 03 Jul 2007 21:06:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Wed, 04 Jul 2007 20:22:30 GMT]]></title><description><![CDATA[<p>kernel64 schrieb:</p>
<blockquote>
<p>... alle Prozesse mit dem gleichen Namen Test.exe haben Unterprogramme geöffnet, ich möchte nun alle Test.exe mit Unterprogramme schließen ...</p>
</blockquote>
<p>Dann besser zwei Funktionen :</p>
<p>Erste Funktion sucht nach &quot;test.exe&quot; und liefert ID zurück falls eine gefunden.<br />
Zweite Funktion nimmt ID und &quot;Child-Flag&quot; und beendet alle Child-Prozesse und am Ende ID.</p>
<p>Dann erste und zweite Funktion sooft aufrufen wie erste Funktion eine ID zurückgibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318535</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 04 Jul 2007 20:22:30 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Wed, 04 Jul 2007 22:40:32 GMT]]></title><description><![CDATA[<p>Hab es nun so gemacht wie du gesagt hast:</p>
<pre><code class="language-cpp">BOOL KillChildProcess(DWORD HauptprogrammID)
{
	HANDLE hProcessSnap = NULL;
	HANDLE hProcess = NULL;
	PROCESSENTRY32 pe32;

	hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}

	do
	{
		if(pe32.th32ParentProcessID == HauptprogrammID)
		{
			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			TerminateProcess(hProcess,0);
			CloseHandle(hProcess);				
		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );
	CloseHandle( hProcessSnap );	

	return TRUE;
}

BOOL KillProcessTree(char *szProcessToKill)
{		
		HANDLE hProcessSnap = NULL;
		HANDLE hProcess = NULL;
		PROCESSENTRY32 pe32;
		//DWORD dwPriorityClass;

		hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( hProcessSnap == INVALID_HANDLE_VALUE )
	{
		printError( &quot;CreateToolhelp32Snapshot (of processes)&quot; );
		return( FALSE );
	}

	pe32.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( hProcessSnap, &amp;pe32 ) )
	{
		printError( &quot;Process32First&quot; );
		CloseHandle( hProcessSnap );
		return( FALSE );
	}	

	do
	{
		//Suche nach Prozessnamen
		if(!strcmp(pe32.szExeFile,szProcessToKill))
		{
			//Beende Child Prozess
			KillChildProcess(pe32.th32ProcessID);

			//Beende Hauptprozess
			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);
			if(TerminateProcess(hProcess,0))
				return TRUE;

			CloseHandle(hProcess);

			cout &lt;&lt; endl;

		}
	} while( Process32Next(hProcessSnap,&amp;pe32) );
	CloseHandle( hProcessSnap );	

	return FALSE;	
}
</code></pre>
<p>Ich habe mehrere Tests durchgeführt und es hat geklappt, falls euch doch was aufallen sollte dann bescheid sagen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
<p>Hatte noch vor den Prozessbaum in der Konsole auch als Baum darzustellen, so z.B.:</p>
<pre><code>+Main.exe
|-Hallo.exe
 |-Test.exe
  |-XYZ.exe
</code></pre>
<p>Wär sowas möglich da doch zuerst der unterste Prozess beendet wird?!?!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318573</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Wed, 04 Jul 2007 22:40:32 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Hauptprogramm mit Unterprogramme schließen? on Thu, 05 Jul 2007 23:09:12 GMT]]></title><description><![CDATA[<p>kernel64 schrieb:</p>
<blockquote>
<p>falls euch doch was aufallen sollte dann bescheid sagen</p>
</blockquote>
<p>Falls ein Child auch noch Child-Prozesse hat, gibt es ein Problem. Aber dann nur das Child als &quot;ProcessTree&quot; betrachten. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>kernel64 schrieb:</p>
<blockquote>
<p>Wär sowas möglich da doch zuerst der unterste Prozess beendet wird?!?!?</p>
</blockquote>
<p>Gib den Prozessnamen an der Stelle aus, wo er <em>gefunden</em> wird und nicht dort, wo er <em>beendet</em> wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1319314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1319314</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 05 Jul 2007 23:09:12 GMT</pubDate></item></channel></rss>