Fix service startup handling

This commit is contained in:
Ron Pedde 2007-03-16 14:04:11 +00:00
parent cf8b867165
commit 0e17b153a3
2 changed files with 17 additions and 2 deletions

View File

@ -226,8 +226,11 @@ DWORD Service::GetStartup() const
bool Service::ConfigureStartup(DWORD startup) {
if(startup != GetStartup()) { // don't boost privs if we don't need to
if (!::ChangeServiceConfig(m_sc_service, SERVICE_NO_CHANGE, startup, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
return false;
if(startup == SERVICE_AUTO_START) {
return ExecHelper(_T("auto"));
} else {
return ExecHelper(_T("manual"));
}
}
return true;
}

View File

@ -11,6 +11,7 @@
#define E_SVC_NORIGHTS 2
#define E_SVC_CANTSTART 3
#define E_SVC_CANTSTOP 4
#define E_SVC_CANTCONFIG 5
// Global Variables:
HINSTANCE hInst; // current instance
@ -121,6 +122,17 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
retval = E_SVC_CANTSTOP;
}
}
if(strcmp(argv[1],"manual")) {
if (!ChangeServiceConfig(svc, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
retval = E_SVC_CANTCONFIG;
}
if(!strcmp(argv[1],"auto")) {
if (!ChangeServiceConfig(svc, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
retval = E_SVC_CANTCONFIG;
}
CloseServiceHandle(svc);
CloseServiceHandle(scm);