<?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[Auf Logoff und Shutdown reagieren?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe eine simple WinApi Applikation die Nach dem &quot;Erkennen&quot; eines Logoff- bzw. Shutdown-Events noch etwas machen soll, aber ich bekomme es irgendwie nicht hin:</p>
<p>Also in der WinMain passiert noch nicht viel, ich Setze die Handler Routine mit SetConsoleCtrlHandler und die liefert auch True zurück.</p>
<p>Ich erzeuge mir vorher noch ein Event, das ich bei shutdown/logoff selber auf signaled setzen möchte. dann warte ich einfach darauf:</p>
<pre><code class="language-cpp">BOOL WINAPI ShutDownHandler(DWORD dwCtrlType)
{
    if((dwCtrlType == CTRL_LOGOFF_EVENT) || (dwCtrlType == CTRL_SHUTDOWN_EVENT))
    {
        // Mach was!
        if (hShutDownEvent) SetEvent(hShutDownEvent);
        return TRUE;
    }
    return FALSE;
}

WinMain(...)
{
    SetConsoleCtrlHandler(ShutDownHandler, TRUE);
    hShutDownEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    DWORD waitResult = WaitForSingleObject(hShutDownEvent, INFINITE);

    return 0;
}
</code></pre>
<p>Es sieht so aus, als ob die Anwendung zwar bei WaitForSingleObject stehen bleibt, aber dann eben auch nicht mehr durch die HandlerRoutine geht <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="😞"
    /></p>
<p>Also mal anders erklärt: Ziel der ganzen Aktion ist: Mein &quot;Service&quot; soll sich erst bei einem Logoff/Shutdown beenden, wie mach ich das am besten?</p>
<p>Hat jemand ein Tip?<br />
Gruß,<br />
mathi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149467/auf-logoff-und-shutdown-reagieren</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 08:18:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149467.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Jun 2006 11:03:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 11:03:15 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe eine simple WinApi Applikation die Nach dem &quot;Erkennen&quot; eines Logoff- bzw. Shutdown-Events noch etwas machen soll, aber ich bekomme es irgendwie nicht hin:</p>
<p>Also in der WinMain passiert noch nicht viel, ich Setze die Handler Routine mit SetConsoleCtrlHandler und die liefert auch True zurück.</p>
<p>Ich erzeuge mir vorher noch ein Event, das ich bei shutdown/logoff selber auf signaled setzen möchte. dann warte ich einfach darauf:</p>
<pre><code class="language-cpp">BOOL WINAPI ShutDownHandler(DWORD dwCtrlType)
{
    if((dwCtrlType == CTRL_LOGOFF_EVENT) || (dwCtrlType == CTRL_SHUTDOWN_EVENT))
    {
        // Mach was!
        if (hShutDownEvent) SetEvent(hShutDownEvent);
        return TRUE;
    }
    return FALSE;
}

WinMain(...)
{
    SetConsoleCtrlHandler(ShutDownHandler, TRUE);
    hShutDownEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    DWORD waitResult = WaitForSingleObject(hShutDownEvent, INFINITE);

    return 0;
}
</code></pre>
<p>Es sieht so aus, als ob die Anwendung zwar bei WaitForSingleObject stehen bleibt, aber dann eben auch nicht mehr durch die HandlerRoutine geht <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="😞"
    /></p>
<p>Also mal anders erklärt: Ziel der ganzen Aktion ist: Mein &quot;Service&quot; soll sich erst bei einem Logoff/Shutdown beenden, wie mach ich das am besten?</p>
<p>Hat jemand ein Tip?<br />
Gruß,<br />
mathi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072368</guid><dc:creator><![CDATA[mathi]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:03:15 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 11:20:28 GMT]]></title><description><![CDATA[<p>Ist das überhaupt ne Konsolenanwendung? Sieht ja nicht danach aus wegen WinMain...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072387</guid><dc:creator><![CDATA[.....]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:20:28 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 11:47:15 GMT]]></title><description><![CDATA[<p>Ach verflixt! <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="😞"
    /> Ich war so Happy endlich was gefunden zu haben, das ich das mit der Konsolen Anwendung glatt verpeilt habe. Ist natürlich keine Konsolen Anwendung.</p>
<p>Wie würde ich denn von einer WinApi Anwendung auf loggof oder shutdown reagieren?</p>
<p>Gruß,<br />
mathi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072411</guid><dc:creator><![CDATA[mathi]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:47:15 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 11:49:00 GMT]]></title><description><![CDATA[<blockquote>
<p>Shutdown Notification</p>
<p>Applications with a window and message queue receive shutdown notification through the WM_QUERYENDSESSION message, unless you call ExitWindowsEx with the EXW_FORCE flag. The applications perform any cleanup while processing WM_QUERYENDSESSION, and return TRUE to indicate that they can be terminated. If you use EXW_FORCE, applications may lose data.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1072414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072414</guid><dc:creator><![CDATA[,,,,,,,]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 11:50:45 GMT]]></title><description><![CDATA[<p>Programmiere doch besser einen echten Dienst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072416</guid><dc:creator><![CDATA[w]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:50:45 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 12:09:25 GMT]]></title><description><![CDATA[<p>w schrieb:</p>
<blockquote>
<p>Programmiere doch besser einen echten Dienst.</p>
</blockquote>
<p>Gibst du mir bitte ein Hinweis, wo ich am besten damit anfange? Ich meine gibts dafür Tutorials?</p>
<p>@,,,,,,,: Danke, aber ich habe keine Fenster, also acuh keine MessageProg <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 />
Na Ok, wenns nich anders geht, bastel ich eben noch ein Fenster rein, im ernstfall</p>
<p>Besten Dank soweit!<br />
Gruß,<br />
mathi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072432</guid><dc:creator><![CDATA[mathi]]></dc:creator><pubDate>Tue, 06 Jun 2006 12:09:25 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Logoff und Shutdown reagieren? on Tue, 06 Jun 2006 12:40:55 GMT]]></title><description><![CDATA[<p>Wie immer mal einfach bei Codeproject schnuppern und siehe da:<br />
<a href="http://www.codeproject.com/system/serviceskeleton.asp" rel="nofollow">http://www.codeproject.com/system/serviceskeleton.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072465</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 06 Jun 2006 12:40:55 GMT</pubDate></item></channel></rss>