Skip to content

Service manager improvments#2841

Merged
obiltschnig merged 10 commits intopocoproject:poco-1.10.0from
KevDi:serviceManagerImprovments
Nov 25, 2019
Merged

Service manager improvments#2841
obiltschnig merged 10 commits intopocoproject:poco-1.10.0from
KevDi:serviceManagerImprovments

Conversation

@KevDi
Copy link
Copy Markdown
Contributor

@KevDi KevDi commented Nov 18, 2019

With the new Constructor it is possible to pass an already existing SC_HANDLE to the WinService Class.
This change allows connections to Service Manager on remote systems. With code like this:

// Create Token for remote user
BOOL result = LogonUser("username", "domain", "password", LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_WINNT50, &hToken);
// Impersonate Token
BOOL impResult = ImpersonateLoggedOnUser(hToken);

//Create Connection to the Remote Service Manager
SC_HANDLE scmHandle = OpenSCManager("addressOfRemoteSystem", NULL, SC_MANAGER_ALL_ACCESS);

// Use the Connection with the WinService Class
WinService spoolerService{scmHandle, "Spooler"};

spoolerService.start();
....

//Reset user token
RevertToSelf()
CloseHandle(hToken)

You also can get the FailureActions for the given service as a vector

WinService spoolerService{"Spooler"};
auto failureActions = spoolerService.getFailureActions();

You could also set the Failure Actions for an Service

WinService spoolerService{"Spooler"};
WinService::FailureActionVector actions{
		{WinService::SVC_REBOOT, 60000},
		{WinService::SVC_RESTART, 60000},
		{WinService::SVC_NONE, 0}
	};
spoolerService_.setFailureActions(actions, "", "");

Now targeting the poco-1.10.0 branch

@obiltschnig obiltschnig self-assigned this Nov 25, 2019
@obiltschnig obiltschnig added this to the Release 1.10.0 milestone Nov 25, 2019
@obiltschnig obiltschnig merged commit e171a60 into pocoproject:poco-1.10.0 Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants