<?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[C++ Befehl den Computer auszuschalten]]></title><description><![CDATA[<p>Gibt es einen Befehl in C++ der den Computer ausschaltet?</p>
<p>Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/100654/c-befehl-den-computer-auszuschalten</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 17:50:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/100654.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Feb 2005 10:20:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:20:35 GMT]]></title><description><![CDATA[<p>Gibt es einen Befehl in C++ der den Computer ausschaltet?</p>
<p>Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/718427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718427</guid><dc:creator><![CDATA[Mortiis]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:20:35 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:25:45 GMT]]></title><description><![CDATA[<p>du musst nen Befehl nehmen , der die Anwendung &quot;shutdown&quot; aufruft</p>
]]></description><link>https://www.c-plusplus.net/forum/post/718429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718429</guid><dc:creator><![CDATA[imson]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:25:45 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:30:47 GMT]]></title><description><![CDATA[<p>Ich hab keine ahnung wie du das meinst. Ich lerne c++ noch nicht lange.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/718432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718432</guid><dc:creator><![CDATA[Mortiis]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:31:44 GMT]]></title><description><![CDATA[<p>@imson _muss_ ? -&gt; nein, es geht auch so:</p>
<pre><code>// Runterfahren des Rechners
//
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &quot;shutdown_rechte.h&quot;
using std::cout;
using std::endl;
using std::cin;

int main(int argc, char * argv[])
{
	for(unsigned int index=0;index&lt;(unsigned)argc;index++)
	if(argv[index][0] == '-')
	{
		switch (argv[index][1])
		{
		case 's':
			SetCurrentPrivilege( SE_SHUTDOWN_NAME, TRUE );
			ExitWindowsEx(8,0);	// Runterfahren
			exit(0);
			break;
		case 'r':
			SetCurrentPrivilege( SE_SHUTDOWN_NAME, TRUE );
			ExitWindowsEx(2,0);	// Neustart
			exit(0);
			break;
		}
	}
	// Setzen der Berechtigungen zum Neustart / Herunterfahren des Systems
	// die Funktion wird in der 'shutdown_rechte.h' abgearbeitet
	SetCurrentPrivilege( SE_SHUTDOWN_NAME, TRUE );

	// Menü zur Auswahl der Art des Herunterfahrens
	char auswahl;
	do{
		cout &lt;&lt; &quot;Runterfahren des Systems, bitte machen Sie Ihre Angaben &quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;--------------------------------------------------------&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Auswahl: &quot; &lt;&lt;  endl;
		cout &lt;&lt; &quot;1 Abmelden&quot; &lt;&lt; endl;								// 0x00000000
		cout &lt;&lt; &quot;2 Runterfahren (nicht Ausschalten)&quot; &lt;&lt; endl;		// 0x00000001
		cout &lt;&lt; &quot;3 Neustart&quot; &lt;&lt; endl;								// 0x00000002
		cout &lt;&lt; &quot;4 Schneller Neustart&quot; &lt;&lt; endl;						// 0x00000004
		cout &lt;&lt; &quot;5 Runterfahren und Ausschalten&quot; &lt;&lt; endl;			// 0x00000008
		cout &lt;&lt; &quot;6 Maustasten vertauschen&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;7 Maustasten wiederherstellen&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;9 Hilfe&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;0 Abbrechen&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;----------------------------------&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Treffen Sie Ihre Auswahl: &quot;;
		cin &gt;&gt; auswahl;
		switch(auswahl)
		{
			case '1':
				ExitWindowsEx(0,0);	// Abmelden
				break;
			case '2':
				ExitWindowsEx(1,0);	// Runterfahren und nicht ausschalten
				break;
			case '3':
				ExitWindowsEx(2,0);	// Neustart
				break;
			case '4':
				ExitWindowsEx(4,0);	// Schneller Neustart
				break;
			case '5':
				ExitWindowsEx(8,0);	// Ausschalten
				break;
			case '6':
				SwapMouseButton(1);
				break;
			case '7':
				SwapMouseButton(0);
				break;
			case '9':
				cout &lt;&lt; &quot;\nshutdown.exe -s Herunterfahren&quot; &lt;&lt; endl;
				cout &lt;&lt; &quot;shutdown.exe -r Neustart\n&quot; &lt;&lt; endl;
				break;
			case '0':
				exit(0);
				break;
			default:
				cout &lt;&lt; &quot;\nFalsche Eingabe, noch einmal...&quot; &lt;&lt; endl;
				break;
		}
	}while(auswahl != 1 || auswahl != 2 || auswahl != 3 || auswahl != 4 || auswahl != 5 || auswahl != 6 || auswahl != 7 || auswahl != 9 || auswahl != 0);
	/*	
	// Nur Runterfahren des Systems
	int timeout = 0, force = 1, reboot = 1;	//Sekunden,Schnelles Booten,Neustart
	{
		InitiateSystemShutdown( NULL,NULL, (DWORD) timeout, force, reboot );
	}
	*/
return 0;
}
</code></pre>
<p>und die header-datei:</p>
<pre><code>// Rechtevergabe zum Herunterfahren des Systems
// BOOL SetCurrentPrivilege( LPCTSTR Privilege, BOOL bEnablePrivilege );
//
BOOL SetCurrentPrivilege( LPCTSTR Privilege, BOOL bEnablePrivilege )
{
	HANDLE hToken;
	LUID luid;
	TOKEN_PRIVILEGES tp, tpPrevious;
	DWORD cbPrevious = sizeof( TOKEN_PRIVILEGES );
	BOOL bSuccess = FALSE;

	if ( ! LookupPrivilegeValue( NULL, Privilege, &amp;luid ) )
		return FALSE;

	if( ! OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &amp;hToken ) )
		return FALSE;

	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	tp.Privileges[0].Attributes = 0;

	AdjustTokenPrivileges( hToken, FALSE, &amp;tp, sizeof( TOKEN_PRIVILEGES ), &amp;tpPrevious, &amp;cbPrevious );

	if ( GetLastError() == ERROR_SUCCESS )
		{
			tpPrevious.PrivilegeCount = 1;
			tpPrevious.Privileges[0].Luid = luid;

			if ( bEnablePrivilege )
				tpPrevious.Privileges[0].Attributes |= ( SE_PRIVILEGE_ENABLED );
			else
				tpPrevious.Privileges[0].Attributes &amp;= ~( SE_PRIVILEGE_ENABLED );

			AdjustTokenPrivileges( hToken, FALSE, &amp;tpPrevious, cbPrevious, NULL, NULL );

			if ( GetLastError() == ERROR_SUCCESS )
				bSuccess=TRUE;
	}
	CloseHandle( hToken );
	return bSuccess;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/718434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718434</guid><dc:creator><![CDATA[enno-tyrant]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:31:44 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:33:30 GMT]]></title><description><![CDATA[<p>OK, danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/718438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718438</guid><dc:creator><![CDATA[Mortiis]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 10:37:48 GMT]]></title><description><![CDATA[<p>Nur für die, die es nicht sowieso schon wissen: Das ist WinAPI und hat mit C++ soviel am Hut wie Sharon mit den Sternsingern. Also, beim nächsten mal in ein passenderes Forum posten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/718443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718443</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Wed, 09 Feb 2005 10:37:48 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Befehl den Computer auszuschalten on Wed, 09 Feb 2005 11:22:21 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/718478</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718478</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Wed, 09 Feb 2005 11:22:21 GMT</pubDate></item></channel></rss>