Skip to content

Start POCO as Windows service with parameters fix #2190#2205

Closed
DomXC wants to merge 1 commit intopocoproject:poco-1.9.1from
DomXC:poco-1.8.2
Closed

Start POCO as Windows service with parameters fix #2190#2205
DomXC wants to merge 1 commit intopocoproject:poco-1.9.1from
DomXC:poco-1.8.2

Conversation

@DomXC
Copy link
Copy Markdown

@DomXC DomXC commented Mar 7, 2018

Args are passed to _argsSvc member using isService, params are appended to params of "Path to executable" service property.

… where args are passed to this member using bool isService(const ArgVec& args); bool isService(int argc, wchar_t** argv); or bool isService(int argc, char** argv);
@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Mar 7, 2018

1.8.2 branch is not valid anymore, it has become 1.9.0, but i'm not sure if @obiltschnig wants to include this for that release. so, this should go against either 1.9.0 or (future) 1.9.1 branch

@DomXC
Copy link
Copy Markdown
Author

DomXC commented Mar 7, 2018

OK, thank you, so, is there any guideline, what to do in this case?
Anyway, build for develop failed (#2204), is there a guideline what to do in this case (I know what is wrong...)? Thank you.

@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Mar 7, 2018

build for develop failed (#2204), is there a guideline what to do in this case (I know what is wrong...)

fix it and push to your branch, changes will show in the pull and CI will trigger again.

@obiltschnig
Copy link
Copy Markdown
Member

Please re-target the pull request to poco-1.9.1 branch.

@DomXC DomXC changed the base branch from poco-1.8.2 to poco-1.9.1 March 7, 2018 16:16
@aleks-f aleks-f added this to the Release 1.9.1 milestone Mar 23, 2018
@obiltschnig
Copy link
Copy Markdown
Member

Please re-target for poco-1.10.0 branch.

@evamueller
Copy link
Copy Markdown

It's not in the 1.10 version, please fix!

@obiltschnig
Copy link
Copy Markdown
Member

Would be great to have a proper PR for the poco-1.10.2 branch.

@intensifi
Copy link
Copy Markdown

The following code reads the "Start Parameters" field of the Service Properties Dialog box. This is very useful for ONE time starts of a service. This is NOT permanent. For that you would have to parse the "Image" registry key for the service. For a FULL feature add, I would suggest that both capabilities by added. The "Start Parameters" field is very useful for one start parameters such as increasing the logging level for problem resolution.

Yes this was a quick hack copying code from a Microsoft support web page.

NOTE: in 1.10.1 on Windows10, unregistering a service does not work. an error message complains about only using /unregisterservice once. No matter though. I just used

sc stop SERVICENAME
sc delete SERVICENAME

in a batch file.


int
main( int argc, char** argv )
{
#if defined(POCO_OS_FAMILY_WINDOWS)
LPWSTR *szArglist = NULL;
int nArgs = 0;
#endif

try
{
	MyClass serverApplication;

	std::vector< std::string > arguments;
	for ( int i = 0; i < argc; ++i )
	{
		arguments.push_back( argv[ i ] );
	}

#if defined(POCO_OS_FAMILY_WINDOWS)
// Windows Services don't process command line arguments like they should!!!
if ( serverApplication.config().getBool( "application.runAsService", false ) )
{
// do service specific things
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs );

		if ( NULL != szArglist )
		{
			for (int i = 0; i < nArgs; i++)
			{
				std::string argument;
				UnicodeConverter::toUTF8( (Poco::UTF16Char*)szArglist[i], argument );
				arguments.push_back(argument);
			}
			LocalFree( szArglist );
			szArglist = NULL;
		}
	}

#endif
return serverApplication.run( arguments );
}

catch ( const Poco::Exception& anException )
{
	std::cerr << anException.displayText() << std::endl;

#if defined(POCO_OS_FAMILY_WINDOWS)
if ( szArglist )
{
LocalFree( szArglist );
}
#endif
}

catch ( const std::exception& )
{

#if defined(POCO_OS_FAMILY_WINDOWS)
if ( szArglist )
{
LocalFree( szArglist );
}
#endif
}

return Poco::Util::Application::EXIT_SOFTWARE;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants