<?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[Service wird als console programm ausgeführt]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen Service geschrieben.<br />
es gibt ein<br />
service.exe install<br />
Wenn das getan ist wird der Service unter dem Tool &quot;Services&quot; angezeigt.</p>
<p>Bei gleichem Quelltext, Compiler und Windows Version kann ich den Service zu Hause starten und stoppen wie ich möchte und er läuft einwandfrei.</p>
<p>An dem PC hier bekomme ich von der Funktion:</p>
<pre><code>ui32_RetVal = StartServiceCtrlDispatcher( DispatchTable );
    if(0x00000000 == ui32_RetVal)
    {
        ui32_RetVal = GetLastError();
        if(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT == ui32_RetVal)
        {
            wsprintf((LPSTR)ui8_DebugString,&quot;StartServiceCtrlDispatcher ERROR_FAILED_SERVICE_CONTROLLER_CONNECT&quot;);
        }else if (ERROR_INVALID_DATA == ui32_RetVal )
.....
</code></pre>
<p>den Fehlercode</p>
<pre><code>ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
</code></pre>
<p>zurück.</p>
<p>Windows meint dazu:</p>
<blockquote>
<p>This error is returned if the program is being run as a console application rather than as a service. If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.</p>
</blockquote>
<p>Also habe ich mal ein</p>
<pre><code>DebugBreak();
</code></pre>
<p>eingebaut welches aufgeführt wird, wenn ich mit dem Tool &quot;Services&quot;<br />
meinen service.exe starte.<br />
Ich erhalte eine Console mit dem Namen &quot;taskeng.exe&quot; welcher dann meldet<br />
service.exe has stopped working.</p>
<p>Ich schließe jetzt, dass mein service.exe von dem tool &quot;Services&quot; nicht als<br />
service sondern als console programm ausgeführt wird.</p>
<p>Jetzt zur Frage:<br />
Gibt es eine möglichkeit Windows7 so zu konfigurieren, dass das tool &quot;Services&quot;<br />
ein Service als Console Programm ausführt ??<br />
Ist das ein berechtigungsproblem ??</p>
<p>Der Eintrag in</p>
<blockquote>
<p>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\service\Type = 0x10</p>
</blockquote>
<p>Was ein eigener Prozess sein sollte.</p>
<p>Ich wäre für Hilfe sehr dankbar, ich sitz an der Sache jetzt schon zwei Tage dran.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/323389/service-wird-als-console-programm-ausgeführt</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 02:44:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323389.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Jan 2014 12:39:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 12:41:12 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen Service geschrieben.<br />
es gibt ein<br />
service.exe install<br />
Wenn das getan ist wird der Service unter dem Tool &quot;Services&quot; angezeigt.</p>
<p>Bei gleichem Quelltext, Compiler und Windows Version kann ich den Service zu Hause starten und stoppen wie ich möchte und er läuft einwandfrei.</p>
<p>An dem PC hier bekomme ich von der Funktion:</p>
<pre><code>ui32_RetVal = StartServiceCtrlDispatcher( DispatchTable );
    if(0x00000000 == ui32_RetVal)
    {
        ui32_RetVal = GetLastError();
        if(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT == ui32_RetVal)
        {
            wsprintf((LPSTR)ui8_DebugString,&quot;StartServiceCtrlDispatcher ERROR_FAILED_SERVICE_CONTROLLER_CONNECT&quot;);
        }else if (ERROR_INVALID_DATA == ui32_RetVal )
.....
</code></pre>
<p>den Fehlercode</p>
<pre><code>ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
</code></pre>
<p>zurück.</p>
<p>Windows meint dazu:</p>
<blockquote>
<p>This error is returned if the program is being run as a console application rather than as a service. If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.</p>
</blockquote>
<p>Also habe ich mal ein</p>
<pre><code>DebugBreak();
</code></pre>
<p>eingebaut welches aufgeführt wird, wenn ich mit dem Tool &quot;Services&quot;<br />
meinen service.exe starte.<br />
Ich erhalte eine Console mit dem Namen &quot;taskeng.exe&quot; welcher dann meldet<br />
service.exe has stopped working.</p>
<p>Ich schließe jetzt, dass mein service.exe von dem tool &quot;Services&quot; nicht als<br />
service sondern als console programm ausgeführt wird.</p>
<p>Jetzt zur Frage:<br />
Gibt es eine möglichkeit Windows7 so zu konfigurieren, dass das tool &quot;Services&quot;<br />
ein Service als Console Programm ausführt ??<br />
Ist das ein berechtigungsproblem ??</p>
<p>Der Eintrag in</p>
<blockquote>
<p>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\service\Type = 0x10</p>
</blockquote>
<p>Was ein eigener Prozess sein sollte.</p>
<p>Ich wäre für Hilfe sehr dankbar, ich sitz an der Sache jetzt schon zwei Tage dran.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380133</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Tue, 28 Jan 2014 12:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 12:48:06 GMT]]></title><description><![CDATA[<p>Okay, also ich habe gerade gesehen, dass ich service.exe<br />
als Windows Task eingetragen hatte.</p>
<p>Wenn ich die Aufgabe raus nehme, fürt &quot;Services&quot; meine service.exe<br />
garnicht mehr aus. Nicht eine Zeile....</p>
<p>Woran kann denn das liegen ??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380138</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Tue, 28 Jan 2014 12:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 12:50:08 GMT]]></title><description><![CDATA[<p>Wird der Dienst denn als gestartet angezeigt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380139</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Tue, 28 Jan 2014 12:50:08 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 13:33:21 GMT]]></title><description><![CDATA[<p>Hi MFK,</p>
<p>nein leider nicht.<br />
Ich benutze DebugView für Fehlerausgaben.<br />
Es wird nichtmal Main aufgerufen.</p>
<pre><code>OutputDebugString(&quot;_tmain -Start (ODS)&quot;);
</code></pre>
<p>Die Ausgabe ist lediglich:</p>
<blockquote>
<p>[5064] FMAPO: DllGetClassObject<br />
[5064] FMAPO: Debug function is disable</p>
</blockquote>
<p>Ich glaube aber nicht dass die Ausgabe was zu bedeuten hat...</p>
<p>Was mich eben extrem wundert ist, das auf meine PC der selbe Service wunderbar startet und stopp.....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380147</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Tue, 28 Jan 2014 13:33:21 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 14:23:39 GMT]]></title><description><![CDATA[<p>Steht denn was im Ereignissprotokoll? Wie ist den der Starttyp des Services?</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380185</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Tue, 28 Jan 2014 14:23:39 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 15:46:28 GMT]]></title><description><![CDATA[<p>Hi Martin,</p>
<p>Danke für die Antwort...</p>
<p>Der Starttyp ist<br />
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\service\Type = 0x10<br />
Also das ist ein eigener W32 prozess...</p>
<p>Wie schon gesagt, auf meinem heimrechner läuft er problemlos...<br />
Ich gluabe nicht dass es am Quelltext liegt...</p>
<p>Eher an der Windows konfiguration...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380217</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Tue, 28 Jan 2014 15:46:28 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Tue, 28 Jan 2014 16:51:16 GMT]]></title><description><![CDATA[<p>NasenBaer_2013 schrieb:</p>
<blockquote>
<p>Eher an der Windows konfiguration...</p>
</blockquote>
<p>Eher an dem wie du das Service auf dem anderen PC registriert hast.<br />
Hätte Windows nämlich ein grundsätzliches Problem damit Services zu starten, dann würde so-gut-wie gar nichts mehr funktionieren.</p>
<p>Versuch' mal dein Service einfach mit <code>sc.exe</code> zu registrieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380234</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 28 Jan 2014 16:51:16 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Wed, 29 Jan 2014 07:17:41 GMT]]></title><description><![CDATA[<p>Guten Morgen Hustbaer,</p>
<p>danke für den Tipp,<br />
aber daran liegt es nicht.</p>
<p>Ich habe den Service mal mit sc create .... installiert.<br />
Die Registryeinträge sind die Selben.<br />
Das Verhalten beim Starten ist äquivalent.</p>
<p>Ich denke das setzt nocheinmal ein Gewicht auf Windowskonfiguration....<br />
Zumal er ja auf meinem Windowsrechner (ziemlich frisch installiert)<br />
einwandfrei läuft.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380325</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Wed, 29 Jan 2014 07:17:41 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Wed, 29 Jan 2014 12:10:44 GMT]]></title><description><![CDATA[<p>Ich habe einmal einen Service implementiert. So wird er bei mir angemeldet:</p>
<pre><code>void TcronconfDlgClient::InstallService()
{
	// INSERT&gt;&gt; Your code here.
	SC_HANDLE		serviceManager;
	SC_HANDLE		jobService;
	char			appPath[1024];
	char			password[64];
	char			username[64];
	char			tmpBuff[64];
	char			*bsPos;
	char			*lastBackSlash;

	serviceManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
	if( serviceManager )
	{
		GetModuleFileName( NULL, appPath, sizeof( appPath ) - 1 );
		lastBackSlash = strrchr( appPath, '\\' );
		if( lastBackSlash )
			lastBackSlash++;

		// stop the dispatcher
		jobService = OpenService( serviceManager, SERVICE_NAME, SERVICE_ALL_ACCESS );
		if( !jobService )
		{
			// create the service
			if( lastBackSlash )
				strcpy( lastBackSlash, &quot;CRONTAB.EXE &quot; );

			// service not yet created

			GetDlgItemText( IDC_PASS_EDIT, password, sizeof( password ) -1 );
			GetDlgItemText( IDC_USER_EDIT, username, sizeof( username ) -1 );
			if( *username )
			{
				bsPos = strchr( username, '\\' );
				if( !bsPos )
				{
					strcpy( tmpBuff, username );
					strcpy( username, &quot;.\\&quot; );
					strcat( username, tmpBuff );
				}
			}

			jobService = CreateService(
							serviceManager,
							SERVICE_NAME,
							SERVICE_NAME,
							SERVICE_ALL_ACCESS,
							SERVICE_WIN32_OWN_PROCESS,
							SERVICE_AUTO_START,
							SERVICE_ERROR_NORMAL,
							appPath,
							NULL, NULL, NULL,
							*username ? username : NULL,
							*username ? password  : NULL );
		}

		if( jobService )
			CloseServiceHandle( jobService );
		else
			MessageBox( &quot;Unable to create job service&quot;, &quot;Error&quot;, MB_OK|MB_ICONERROR );

		CloseServiceHandle( serviceManager );
	}
	else
		MessageBox( &quot;Unable to open service manager&quot;, &quot;FATAL&quot;, 0 );

	checkService();
}
</code></pre>
<p>Dafür benötigt der Benutzer natürlich Adminrechte.</p>
<p>Im Service sieht das dann so aus:</p>
<pre><code>#ifdef RUN_AS_SERVICE
static void WINAPI MyServiceCtrlHandler ( DWORD Opcode )
{
	switch( Opcode )
	{
	case SERVICE_CONTROL_PAUSE:
		servicePaused = 1;
		MyServiceStatus.dwCurrentState = SERVICE_PAUSED;
		break;

	case SERVICE_CONTROL_CONTINUE:
		servicePaused = 0;
		MyServiceStatus.dwCurrentState = SERVICE_RUNNING;
		break;

	case SERVICE_CONTROL_STOP:
		serviceStopped = 1;
		MyServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
		MyServiceStatus.dwWin32ExitCode = 0;
		MyServiceStatus.dwCheckPoint    = 0;
		MyServiceStatus.dwWaitHint      = 0;
		break;

	case SERVICE_CONTROL_INTERROGATE:
		break;
	 }

	SetServiceStatus (MyServiceStatusHandle,  &amp;MyServiceStatus);
	return;
}

static void WINAPI ServiceMain( DWORD , LPSTR * )
{
	// for a service we only register the control handler no log window
	MyServiceStatus.dwServiceType        = SERVICE_WIN32_OWN_PROCESS;
	MyServiceStatus.dwCurrentState       = SERVICE_START_PENDING;
	MyServiceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE;
	MyServiceStatus.dwWin32ExitCode      = 0;
	MyServiceStatus.dwServiceSpecificExitCode = 0;
	MyServiceStatus.dwCheckPoint         = 0;
	MyServiceStatus.dwWaitHint           = 0;

	MyServiceStatusHandle = RegisterServiceCtrlHandler(
							SERVICE_NAME,
							MyServiceCtrlHandler);

	MyServiceStatus.dwCurrentState       = SERVICE_RUNNING;
	MyServiceStatus.dwCheckPoint         = 0;
	MyServiceStatus.dwWaitHint           = 0;

	SetServiceStatus( MyServiceStatusHandle, &amp;MyServiceStatus );

	StartServiceThread();

	MyServiceStatus.dwCurrentState       = SERVICE_STOPPED;
	MyServiceStatus.dwCheckPoint         = 0;
	MyServiceStatus.dwWaitHint           = 0;

	SetServiceStatus (MyServiceStatusHandle, &amp;MyServiceStatus);
}
#endif

int main( int , char ** )
{
#ifdef RUN_AS_SERVICE
	SERVICE_TABLE_ENTRY   DispatchTable[] =
	{
		{ SERVICE_NAME,	ServiceMain		},
		{ NULL,			NULL			}
	};

	StartServiceCtrlDispatcher( DispatchTable );
#else
	StartServiceThread();
#endif
	return 0;
}
</code></pre>
<p>Der Service wurde bei mir als Win32-Console-Anwendung übersetzt.</p>
<p>Früher gab es auch, wenn ich mich recht erinnere, tatsächlich eine Option, mit der das konfiguriert werden konnte. Irgendwas mit interaktiv oder so ähnlich. Wie ist denn beim Reiter Anmelden der Schalter &quot;Datenaustausch mit dem Desktop zulassen&quot; gesetzt?</p>
<p>Vielleicht hilft Dir das.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380357</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Wed, 29 Jan 2014 12:10:44 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Wed, 29 Jan 2014 12:28:05 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30336">@NasenBaer_2013</a><br />
Mach mal ein kleines Test-Programm, das nur den <code>StartServiceCtrlDispatcher</code> Aufruf enthält und dessen Returnwert rausloggt. Kein Code zum Installieren oder sonstwas.<br />
Und dann installier' das mal mit <code>sc.exe YourName create type= own binPath= x:\your\path\to\the.exe DisplayName= YourDisplayName</code> und probier es zu starten.</p>
<p>Und natürlich musst du das Service wo ablegen wo der Service-Account die nötigen Berechtigungen hat - was bei LocalSystem (Default) aber normalerweise kein Problem sein sollte.</p>
<p>Wenn es damit geht, dann bau dieses kleine Programm Schritt für Schritt in das um was du jetzt hast, und probier nach jedem Schritt ob es noch funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380363</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 29 Jan 2014 12:28:05 GMT</pubDate></item><item><title><![CDATA[Reply to Service wird als console programm ausgeführt on Wed, 29 Jan 2014 16:22:34 GMT]]></title><description><![CDATA[<p>Guten Abend mgaeckler und hustbaer,</p>
<p>vielen Dank für eure Mühe...</p>
<p>Na ja ich habe jetzt zurück bekommen, dass<br />
services explizit abgeschalten wurden wenn ich den aussagen glauben darf.</p>
<p>Ich werds nochmal versuchen,<br />
aber das schaut gleich aus wie bei mir auch...</p>
<p>Sorry dass ihr euch die Mühe gemacht habt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2380452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2380452</guid><dc:creator><![CDATA[NasenBaer_2013]]></dc:creator><pubDate>Wed, 29 Jan 2014 16:22:34 GMT</pubDate></item></channel></rss>