<?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[Windows Dienst gibt kein Lebenszeichen von sich]]></title><description><![CDATA[<p>Ich habe mir einen Windows Service geschrieben.</p>
<p>Den Quellcode habe ich größtenteils aus der MSDN.</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;fstream&gt;

using namespace std;

SERVICE_STATUS Serv_status;
SERVICE_STATUS_HANDLE hServ_status;

VOID WINAPI MyServiceCtrlHandler (DWORD Opcode) 
{ 
   DWORD status; 

   switch(Opcode) 
   { 
      case SERVICE_CONTROL_PAUSE: 
      // Do whatever it takes to pause here. 
         Serv_status.dwCurrentState = SERVICE_PAUSED; 
         break; 

      case SERVICE_CONTROL_CONTINUE: 
      // Do whatever it takes to continue here. 
         Serv_status.dwCurrentState = SERVICE_RUNNING; 
         break; 

      case SERVICE_CONTROL_STOP: 
      // Do whatever it takes to stop here. 
         Serv_status.dwWin32ExitCode = 0; 
         Serv_status.dwCurrentState  = SERVICE_STOPPED; 
         Serv_status.dwCheckPoint    = 0; 
         Serv_status.dwWaitHint      = 0; 

         SetServiceStatus (hServ_status, &amp;Serv_status);

         return; 

      case SERVICE_CONTROL_INTERROGATE: 
      // Fall through to send current status. 
         break;   
   } 
   SetServiceStatus (hServ_status, &amp;Serv_status);
   // Send current status. 

   return; 
} 

void WINAPI MyServiceStart (DWORD argc, LPTSTR *argv) 
{ 
    DWORD status; 
    DWORD specificError; 

    Serv_status.dwServiceType        = SERVICE_WIN32; 
    Serv_status.dwCurrentState       = SERVICE_START_PENDING; 
    Serv_status.dwControlsAccepted   = 0; 
    Serv_status.dwWin32ExitCode      = 0; 
    Serv_status.dwServiceSpecificExitCode = 0; 
    Serv_status.dwCheckPoint         = 0; 
    Serv_status.dwWaitHint           = 10000; 

    hServ_status = RegisterServiceCtrlHandler( 
        &quot;MyService&quot;, 
        MyServiceCtrlHandler); 

    SetServiceStatus(hServ_status, &amp;Serv_status);

    // Handle error condition 
    if (status != NO_ERROR) 
    { 
        Serv_status.dwCurrentState       = SERVICE_STOPPED; 
        Serv_status.dwCheckPoint         = 0; 
        Serv_status.dwWaitHint           = 0; 
        Serv_status.dwWin32ExitCode      = status; 
        Serv_status.dwServiceSpecificExitCode = specificError; 

        SetServiceStatus (hServ_status, &amp;Serv_status); 
        return; 
    } 

    // Initialization complete - report running status. 
    Serv_status.dwCurrentState       = SERVICE_RUNNING; 
    Serv_status.dwCheckPoint         = 0; 
    Serv_status.dwWaitHint           = 0; 
    Serv_status.dwControlsAccepted   = SERVICE_ACCEPT_STOP |
        SERVICE_ACCEPT_PAUSE_CONTINUE;

    SetServiceStatus (hServ_status, &amp;Serv_status);
    Beep( 750, 3000 );//Warum beept er hier nicht???
    fstream f;
    f.open(&quot;C:\\service_test.txt&quot;, ios::out);
    f &lt;&lt; &quot;Der Dienst laeuft.&quot; &lt;&lt; endl;
    f.close();
    // This is where the service does its work. 
    return; 
}

int main(int argc, char *argv[])
{
    SERVICE_TABLE_ENTRY serv_dispatchtable[]=
    {
                        {TEXT(&quot;MyService&quot;),(LPSERVICE_MAIN_FUNCTION)MyServiceStart},
                        {NULL,NULL}
    };
    StartServiceCtrlDispatcher(serv_dispatchtable);
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Allerdings gibt der Dienst kein Lebenszeichen von sich.<br />
Das heißt er beept nicht und er schreibt auch nix in die txt Datei.</p>
<p>Wie kann ich also testen was nicht funktioniert??<br />
Vllt findet ihr ja auch nen Fehler;</p>
<p>MFG<br />
Ace</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/173958/windows-dienst-gibt-kein-lebenszeichen-von-sich</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 23:49:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173958.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Feb 2007 15:31:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Windows Dienst gibt kein Lebenszeichen von sich on Wed, 21 Feb 2007 15:31:15 GMT]]></title><description><![CDATA[<p>Ich habe mir einen Windows Service geschrieben.</p>
<p>Den Quellcode habe ich größtenteils aus der MSDN.</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;fstream&gt;

using namespace std;

SERVICE_STATUS Serv_status;
SERVICE_STATUS_HANDLE hServ_status;

VOID WINAPI MyServiceCtrlHandler (DWORD Opcode) 
{ 
   DWORD status; 

   switch(Opcode) 
   { 
      case SERVICE_CONTROL_PAUSE: 
      // Do whatever it takes to pause here. 
         Serv_status.dwCurrentState = SERVICE_PAUSED; 
         break; 

      case SERVICE_CONTROL_CONTINUE: 
      // Do whatever it takes to continue here. 
         Serv_status.dwCurrentState = SERVICE_RUNNING; 
         break; 

      case SERVICE_CONTROL_STOP: 
      // Do whatever it takes to stop here. 
         Serv_status.dwWin32ExitCode = 0; 
         Serv_status.dwCurrentState  = SERVICE_STOPPED; 
         Serv_status.dwCheckPoint    = 0; 
         Serv_status.dwWaitHint      = 0; 

         SetServiceStatus (hServ_status, &amp;Serv_status);

         return; 

      case SERVICE_CONTROL_INTERROGATE: 
      // Fall through to send current status. 
         break;   
   } 
   SetServiceStatus (hServ_status, &amp;Serv_status);
   // Send current status. 

   return; 
} 

void WINAPI MyServiceStart (DWORD argc, LPTSTR *argv) 
{ 
    DWORD status; 
    DWORD specificError; 

    Serv_status.dwServiceType        = SERVICE_WIN32; 
    Serv_status.dwCurrentState       = SERVICE_START_PENDING; 
    Serv_status.dwControlsAccepted   = 0; 
    Serv_status.dwWin32ExitCode      = 0; 
    Serv_status.dwServiceSpecificExitCode = 0; 
    Serv_status.dwCheckPoint         = 0; 
    Serv_status.dwWaitHint           = 10000; 

    hServ_status = RegisterServiceCtrlHandler( 
        &quot;MyService&quot;, 
        MyServiceCtrlHandler); 

    SetServiceStatus(hServ_status, &amp;Serv_status);

    // Handle error condition 
    if (status != NO_ERROR) 
    { 
        Serv_status.dwCurrentState       = SERVICE_STOPPED; 
        Serv_status.dwCheckPoint         = 0; 
        Serv_status.dwWaitHint           = 0; 
        Serv_status.dwWin32ExitCode      = status; 
        Serv_status.dwServiceSpecificExitCode = specificError; 

        SetServiceStatus (hServ_status, &amp;Serv_status); 
        return; 
    } 

    // Initialization complete - report running status. 
    Serv_status.dwCurrentState       = SERVICE_RUNNING; 
    Serv_status.dwCheckPoint         = 0; 
    Serv_status.dwWaitHint           = 0; 
    Serv_status.dwControlsAccepted   = SERVICE_ACCEPT_STOP |
        SERVICE_ACCEPT_PAUSE_CONTINUE;

    SetServiceStatus (hServ_status, &amp;Serv_status);
    Beep( 750, 3000 );//Warum beept er hier nicht???
    fstream f;
    f.open(&quot;C:\\service_test.txt&quot;, ios::out);
    f &lt;&lt; &quot;Der Dienst laeuft.&quot; &lt;&lt; endl;
    f.close();
    // This is where the service does its work. 
    return; 
}

int main(int argc, char *argv[])
{
    SERVICE_TABLE_ENTRY serv_dispatchtable[]=
    {
                        {TEXT(&quot;MyService&quot;),(LPSERVICE_MAIN_FUNCTION)MyServiceStart},
                        {NULL,NULL}
    };
    StartServiceCtrlDispatcher(serv_dispatchtable);
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Allerdings gibt der Dienst kein Lebenszeichen von sich.<br />
Das heißt er beept nicht und er schreibt auch nix in die txt Datei.</p>
<p>Wie kann ich also testen was nicht funktioniert??<br />
Vllt findet ihr ja auch nen Fehler;</p>
<p>MFG<br />
Ace</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1232688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1232688</guid><dc:creator><![CDATA[AceKiller73]]></dc:creator><pubDate>Wed, 21 Feb 2007 15:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to Windows Dienst gibt kein Lebenszeichen von sich on Thu, 22 Feb 2007 08:29:03 GMT]]></title><description><![CDATA[<p>Ist der Service überhaupt installiert.<br />
Platziere doch einfach mal DebugBreak am Anfang Deine Routine. Dann kanst Du Debuggen.</p>
<p>Ansonsten empfehele ich lesen:<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms810429.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms810429.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1232991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1232991</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Thu, 22 Feb 2007 08:29:03 GMT</pubDate></item></channel></rss>