<?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[Mit Dienst Programm überwachen]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe mal wieder ein Problem <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>Ich habe ein Programm geschrieben, welches immer laufen soll, und auch nicht vom Benutzer beendet werden soll. Jetzt habe ich einen Dienst geschrieben, welcher Überprüft ob mein Programm läuft, und falls nicht das Programm erneut startet. Dies funktioniert leider nur beim ersten mal. wenn ich mein Programm dann erneut beende, wird es nicht mehr gestartet.</p>
<p>Hier mein Quellcode:</p>
<p>Timer:</p>
<pre><code class="language-cpp">void __fastcall TService1::Timer2Timer(TObject *Sender)
{
   if ( hNote ){
      DWORD noteExitCode;
      if ( GetExitCodeProcess(hNote , &amp;noteExitCode) ) {
         if ( noteExitCode== STILL_ACTIVE ) {
            // immer noch an
         }
         else {
            CloseHandle( hNote );
            hNote = ExecuteProcess(&quot;C:\\Puffer\\STLkonverter.exe&quot;, GetCurrentDir() );
         }
      }
   }
   else{
       hNote = ExecuteProcess(&quot;C:\\Puffer\\STLkonverter.exe&quot;, GetCurrentDir() );
   }
}
</code></pre>
<p>ExecuteProcess:</p>
<pre><code class="language-cpp">HANDLE __fastcall TService1::ExecuteProcess( const String &amp; CommandLine, const String &amp; WorkDir )
{  STARTUPINFO sStartInfo;
   ZeroMemory( &amp;sStartInfo, sizeof(STARTUPINFO) );
   sStartInfo.cb = sizeof(STARTUPINFO);
   sStartInfo.wShowWindow = SW_SHOWDEFAULT;
   sStartInfo.dwFlags = STARTF_USESHOWWINDOW;

   SECURITY_ATTRIBUTES sa;
   HANDLE hReadPipe, hWritePipe;
   char Buffer[4000];
   DWORD dwRead;

   sa.nLength = sizeof (SECURITY_ATTRIBUTES);
   sa.lpSecurityDescriptor = NULL;
   sa.bInheritHandle = true;
   CreatePipe(&amp;hReadPipe, &amp;hWritePipe, &amp;sa, 2500000);

   memset(&amp;sStartInfo, 0, sizeof(STARTUPINFO));
   sStartInfo.cb = sizeof (STARTUPINFO);
   sStartInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
   sStartInfo.wShowWindow = SW_HIDE;
   sStartInfo.hStdOutput = hWritePipe;
   PROCESS_INFORMATION sProcessInfo;
   ZeroMemory( &amp;sProcessInfo, sizeof(PROCESS_INFORMATION) );

   bool ok = CreateProcess( NULL, CommandLine.c_str(),
                           NULL, NULL, true,
                           NORMAL_PRIORITY_CLASS, NULL, WorkDir.c_str() , &amp;sStartInfo, &amp;sProcessInfo );

   if ( !ok ) {
      sProcessInfo.hProcess = 0;
   }
   else{
      WaitForSingleObject(sProcessInfo.hProcess, 30000);
      ReadFile(hReadPipe,&amp;Buffer,sizeof(Buffer), &amp;dwRead, NULL);
      int i=0;
      AnsiString strOut=&quot;&quot;;
      while (Buffer[i]) {
        strOut=strOut+Buffer[i++];
      }
      RichEdit1-&gt;Add(strOut);
   }
   return sProcessInfo.hProcess;
}
</code></pre>
<p>Kann mir irgendwer sagen, warum es nur einmal ausgeführt wird?</p>
<p>Danke für die Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/143675/mit-dienst-programm-überwachen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 23:44:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/143675.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Apr 2006 18:41:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Mon, 10 Apr 2006 18:41:59 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe mal wieder ein Problem <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>Ich habe ein Programm geschrieben, welches immer laufen soll, und auch nicht vom Benutzer beendet werden soll. Jetzt habe ich einen Dienst geschrieben, welcher Überprüft ob mein Programm läuft, und falls nicht das Programm erneut startet. Dies funktioniert leider nur beim ersten mal. wenn ich mein Programm dann erneut beende, wird es nicht mehr gestartet.</p>
<p>Hier mein Quellcode:</p>
<p>Timer:</p>
<pre><code class="language-cpp">void __fastcall TService1::Timer2Timer(TObject *Sender)
{
   if ( hNote ){
      DWORD noteExitCode;
      if ( GetExitCodeProcess(hNote , &amp;noteExitCode) ) {
         if ( noteExitCode== STILL_ACTIVE ) {
            // immer noch an
         }
         else {
            CloseHandle( hNote );
            hNote = ExecuteProcess(&quot;C:\\Puffer\\STLkonverter.exe&quot;, GetCurrentDir() );
         }
      }
   }
   else{
       hNote = ExecuteProcess(&quot;C:\\Puffer\\STLkonverter.exe&quot;, GetCurrentDir() );
   }
}
</code></pre>
<p>ExecuteProcess:</p>
<pre><code class="language-cpp">HANDLE __fastcall TService1::ExecuteProcess( const String &amp; CommandLine, const String &amp; WorkDir )
{  STARTUPINFO sStartInfo;
   ZeroMemory( &amp;sStartInfo, sizeof(STARTUPINFO) );
   sStartInfo.cb = sizeof(STARTUPINFO);
   sStartInfo.wShowWindow = SW_SHOWDEFAULT;
   sStartInfo.dwFlags = STARTF_USESHOWWINDOW;

   SECURITY_ATTRIBUTES sa;
   HANDLE hReadPipe, hWritePipe;
   char Buffer[4000];
   DWORD dwRead;

   sa.nLength = sizeof (SECURITY_ATTRIBUTES);
   sa.lpSecurityDescriptor = NULL;
   sa.bInheritHandle = true;
   CreatePipe(&amp;hReadPipe, &amp;hWritePipe, &amp;sa, 2500000);

   memset(&amp;sStartInfo, 0, sizeof(STARTUPINFO));
   sStartInfo.cb = sizeof (STARTUPINFO);
   sStartInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
   sStartInfo.wShowWindow = SW_HIDE;
   sStartInfo.hStdOutput = hWritePipe;
   PROCESS_INFORMATION sProcessInfo;
   ZeroMemory( &amp;sProcessInfo, sizeof(PROCESS_INFORMATION) );

   bool ok = CreateProcess( NULL, CommandLine.c_str(),
                           NULL, NULL, true,
                           NORMAL_PRIORITY_CLASS, NULL, WorkDir.c_str() , &amp;sStartInfo, &amp;sProcessInfo );

   if ( !ok ) {
      sProcessInfo.hProcess = 0;
   }
   else{
      WaitForSingleObject(sProcessInfo.hProcess, 30000);
      ReadFile(hReadPipe,&amp;Buffer,sizeof(Buffer), &amp;dwRead, NULL);
      int i=0;
      AnsiString strOut=&quot;&quot;;
      while (Buffer[i]) {
        strOut=strOut+Buffer[i++];
      }
      RichEdit1-&gt;Add(strOut);
   }
   return sProcessInfo.hProcess;
}
</code></pre>
<p>Kann mir irgendwer sagen, warum es nur einmal ausgeführt wird?</p>
<p>Danke für die Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1034742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1034742</guid><dc:creator><![CDATA[? ? ? ?]]></dc:creator><pubDate>Mon, 10 Apr 2006 18:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Mon, 10 Apr 2006 19:15:41 GMT]]></title><description><![CDATA[<p>Wird der Timer wieder neu gestartet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1034765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1034765</guid><dc:creator><![CDATA[Rostfrei**]]></dc:creator><pubDate>Mon, 10 Apr 2006 19:15:41 GMT</pubDate></item><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Tue, 11 Apr 2006 04:30:22 GMT]]></title><description><![CDATA[<p>Wo wird der Timer beendet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1034873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1034873</guid><dc:creator><![CDATA[Christian211]]></dc:creator><pubDate>Tue, 11 Apr 2006 04:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Tue, 11 Apr 2006 06:54:21 GMT]]></title><description><![CDATA[<p>? ? ? ? schrieb:</p>
<blockquote>
<p>Dies funktioniert leider nur beim ersten mal. wenn ich mein Programm dann erneut beende, wird es nicht mehr gestartet.</p>
</blockquote>
<p>wird der OnTimerEvent aufgerufen? wo im Code läuft was falsch?<br />
ohne genäuere fehlbeschreibung oder geld für eine neue Kristallkugel wird das warscheinlich nichts</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1034902</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1034902</guid><dc:creator><![CDATA[BigNeal]]></dc:creator><pubDate>Tue, 11 Apr 2006 06:54:21 GMT</pubDate></item><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Tue, 11 Apr 2006 13:34:05 GMT]]></title><description><![CDATA[<p>Mal n'par Vermutungen zu ExecuteProcess:<br />
1. HANDLEs weden ungültig -&gt; CreatePipe(&amp;hReadPipe, &amp;hWritePipe, &amp;sa, 2500000);<br />
2. -&gt; WaitForSingleObject(sProcessInfo.hProcess, 30000); ?? 30 Sek nichts machen<br />
bis<br />
RichEdit1-&gt;Add(strOut); ?? wo ist im Service ein RichEdit</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035257</guid><dc:creator><![CDATA[thomas1]]></dc:creator><pubDate>Tue, 11 Apr 2006 13:34:05 GMT</pubDate></item><item><title><![CDATA[Reply to Mit Dienst Programm überwachen on Tue, 11 Apr 2006 18:10:00 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>danke habe die Fehler gefunden.</p>
<p>thomas1 hatte Recht, da war ein haufen unnützes Zeug drinne.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035459</guid><dc:creator><![CDATA[? ? ? ?]]></dc:creator><pubDate>Tue, 11 Apr 2006 18:10:00 GMT</pubDate></item></channel></rss>