<?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[Den Status eines Windows-Dienstes abfragen]]></title><description><![CDATA[<p>Hallo,</p>
<p>hier ist mein Ansatz mit dem ich versuche den Status eines Dienstes unter Windows 2000 abzufragen.<br />
Weshalb es zu diesen Fehlern kommt kann ich mir dennoch nicht erklären.<br />
Vielleicht weiss ja jemand weiter oder hat einen guten Tipp <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="😉"
    /><br />
Danke.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
using namespace std;
int main()

{
SC_HANDLE ServDataBase;
if(OpenSCManager(NULL, //local
							 SERVICES_ACTIVE_DATABASE, // name of the service control manager database to open
							 SC_MANAGER_ALL_ACCESS // includes STANDARD_RIGHTS_REQUIRED
							 )==NULL)
{
	cout &lt;&lt; &quot;FAILED&quot; &lt;&lt; endl;
}

unsigned long iNumberofServices;
unsigned long pcbBytesNeeded;

ENUM_SERVICE_STATUS ServStat;
ServStat.lpServiceName=&quot;TlntSvr&quot;; // name of service
ServStat.lpDisplayName=&quot;Telnet&quot;;  // display name

// access the SERVICE_STATUS struct to specify detailed information:
ServStat.ServiceStatus.dwServiceType=SERVICE_WIN32_SHARE_PROCESS;
ServStat.ServiceStatus.dwCurrentState=SERVICE_RUNNING;
ServStat.ServiceStatus.dwControlsAccepted=SERVICE_ACCEPT_PAUSE_CONTINUE;

cout &lt;&lt; &quot;1st Error: &quot; &lt;&lt; GetLastError() &lt;&lt; endl; // returns Error 997, Overlapped I/O operation is in progress.

int iEnReturn;

iEnReturn = EnumServicesStatus(ServDataBase, 
				   SERVICE_WIN32,
				   SERVICE_STATE_ALL,
				   &amp;ServStat,
				   sizeof(ServStat),
				   &amp;pcbBytesNeeded,
				   &amp;iNumberofServices,
				   0);

{
	cout &lt;&lt; GetLastError() &lt;&lt; endl; // returns Error 234 
	cout &lt;&lt; iEnReturn &lt;&lt; endl; // returns 0 &lt;&lt;-- that means it did not succeed

}

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/122450/den-status-eines-windows-dienstes-abfragen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 11:16:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/122450.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 Oct 2005 20:43:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Wed, 05 Oct 2005 20:43:38 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>hier ist mein Ansatz mit dem ich versuche den Status eines Dienstes unter Windows 2000 abzufragen.<br />
Weshalb es zu diesen Fehlern kommt kann ich mir dennoch nicht erklären.<br />
Vielleicht weiss ja jemand weiter oder hat einen guten Tipp <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="😉"
    /><br />
Danke.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
using namespace std;
int main()

{
SC_HANDLE ServDataBase;
if(OpenSCManager(NULL, //local
							 SERVICES_ACTIVE_DATABASE, // name of the service control manager database to open
							 SC_MANAGER_ALL_ACCESS // includes STANDARD_RIGHTS_REQUIRED
							 )==NULL)
{
	cout &lt;&lt; &quot;FAILED&quot; &lt;&lt; endl;
}

unsigned long iNumberofServices;
unsigned long pcbBytesNeeded;

ENUM_SERVICE_STATUS ServStat;
ServStat.lpServiceName=&quot;TlntSvr&quot;; // name of service
ServStat.lpDisplayName=&quot;Telnet&quot;;  // display name

// access the SERVICE_STATUS struct to specify detailed information:
ServStat.ServiceStatus.dwServiceType=SERVICE_WIN32_SHARE_PROCESS;
ServStat.ServiceStatus.dwCurrentState=SERVICE_RUNNING;
ServStat.ServiceStatus.dwControlsAccepted=SERVICE_ACCEPT_PAUSE_CONTINUE;

cout &lt;&lt; &quot;1st Error: &quot; &lt;&lt; GetLastError() &lt;&lt; endl; // returns Error 997, Overlapped I/O operation is in progress.

int iEnReturn;

iEnReturn = EnumServicesStatus(ServDataBase, 
				   SERVICE_WIN32,
				   SERVICE_STATE_ALL,
				   &amp;ServStat,
				   sizeof(ServStat),
				   &amp;pcbBytesNeeded,
				   &amp;iNumberofServices,
				   0);

{
	cout &lt;&lt; GetLastError() &lt;&lt; endl; // returns Error 234 
	cout &lt;&lt; iEnReturn &lt;&lt; endl; // returns 0 &lt;&lt;-- that means it did not succeed

}

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/886052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886052</guid><dc:creator><![CDATA[Airspray]]></dc:creator><pubDate>Wed, 05 Oct 2005 20:43:38 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Wed, 05 Oct 2005 20:47:56 GMT]]></title><description><![CDATA[<p>234, Es sind mehr Daten verfügbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/886054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886054</guid><dc:creator><![CDATA[123]]></dc:creator><pubDate>Wed, 05 Oct 2005 20:47:56 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Wed, 05 Oct 2005 20:50:42 GMT]]></title><description><![CDATA[<p>Aber was bedeutet das?<br />
Ich kann mit der Fehlermeldung nichts anfangen genauso wie mit dem Erro 997.<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/886056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886056</guid><dc:creator><![CDATA[Airspray]]></dc:creator><pubDate>Wed, 05 Oct 2005 20:50:42 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Wed, 05 Oct 2005 20:54:06 GMT]]></title><description><![CDATA[<p>erstmal macht es nur sinn GetLastError aufzurfen, wenn die funktion fehlgeschlagen ist.</p>
<p>und zum problem mit mehr daten. du musst wahrscheinlich EnumServicesStatus ein zweites mal aufrufen, aber dann mit der richtigen größe die du ja beim ersten aufruf durch pcbBytesNeeded bekommen hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/886058</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886058</guid><dc:creator><![CDATA[123]]></dc:creator><pubDate>Wed, 05 Oct 2005 20:54:06 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Wed, 05 Oct 2005 21:04:35 GMT]]></title><description><![CDATA[<p>Aha, okay.<br />
Mit dem ErrorHandling hast du natürlich vollkommen recht.</p>
<p>pcbBytesNeeded = 5878 (Bytes)</p>
<p>Wie mache ich das dann mit dem zweiten Aufruf?<br />
Der letzte Parameter heisst der Funktion ist bei mir ja 0.<br />
In MSDN heisst er lpResumeHandle [in, out].<br />
Beim ersten Aufruf muss dieser 0 sein so wie ich es mache.</p>
<p>Wie schaut dann der zweite Aufruf aus?</p>
<p>Dank dir mal <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>
]]></description><link>https://www.c-plusplus.net/forum/post/886067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886067</guid><dc:creator><![CDATA[Airspray]]></dc:creator><pubDate>Wed, 05 Oct 2005 21:04:35 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Fri, 07 Oct 2005 09:47:26 GMT]]></title><description><![CDATA[<p>Wenn Du den Status von einem Dienst haben willst, statt alle Dienste aufzulisten, dann kannst Du es so machen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
using namespace std;

#pragma comment( lib, &quot;Advapi32.lib&quot; )

int main()
{
	SC_HANDLE ServDataBase = OpenSCManager( NULL, //local
								 SERVICES_ACTIVE_DATABASE, // name of the service control manager database to open
								 SC_MANAGER_ALL_ACCESS // includes STANDARD_RIGHTS_REQUIRED
								 );

	if( !ServDataBase )
	{
		cout &lt;&lt; &quot;FAILED&quot; &lt;&lt; endl;
		return 1;
	}

	SC_HANDLE hService = OpenService( ServDataBase, &quot;TlntSvr&quot;, SC_MANAGER_ALL_ACCESS );
	SERVICE_STATUS ss;

	if( hService )
	{
		bool bQuery = QueryServiceStatus( hService, &amp;ss );

		if( bQuery )
			switch( ss.dwCurrentState )
			{
				case SERVICE_STOPPED:
					cout &lt;&lt; &quot;Service gestoppt!&quot; &lt;&lt; endl;
					break;
				case SERVICE_START_PENDING:
					cout &lt;&lt; &quot;Service wird gestartet...&quot; &lt;&lt; endl;
					break;
				case SERVICE_STOP_PENDING:
					cout &lt;&lt; &quot;Service wird gestoppt&quot; &lt;&lt; endl;
					break;
				case SERVICE_RUNNING:
					cout &lt;&lt; &quot;Service läuft...&quot; &lt;&lt; endl;
					break;
				case SERVICE_CONTINUE_PENDING:
					cout &lt;&lt; &quot;Service wird fortgeführt...&quot; &lt;&lt; endl;
					break;
				case SERVICE_PAUSE_PENDING:
					cout &lt;&lt; &quot;Service wird angehalten...&quot; &lt;&lt; endl;
					break;
				case SERVICE_PAUSED:
					cout &lt;&lt; &quot;Service angehalten!&quot; &lt;&lt; endl;
					break;
			}
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/886913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/886913</guid><dc:creator><![CDATA[Airdamn]]></dc:creator><pubDate>Fri, 07 Oct 2005 09:47:26 GMT</pubDate></item><item><title><![CDATA[Reply to Den Status eines Windows-Dienstes abfragen on Fri, 07 Oct 2005 22:33:13 GMT]]></title><description><![CDATA[<p>Wow super, genau das habe ich gesucht!<br />
Vielen Dank für deine Mühe!!! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/887483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/887483</guid><dc:creator><![CDATA[Airspray]]></dc:creator><pubDate>Fri, 07 Oct 2005 22:33:13 GMT</pubDate></item></channel></rss>