Start + Stop service

This commit is contained in:
Naim A 2016-02-20 21:13:09 +02:00
parent 7d27979828
commit 4b26c85917
2 changed files with 18 additions and 1 deletions

View file

@ -182,6 +182,11 @@ int main(int argc, char *argv[])
{ {
svc.stop(); svc.stop();
} }
else
{
std::cerr << "No such service command." << std::endl;
return -1;
}
} }
catch (const UDPT::OSError& ex) catch (const UDPT::OSError& ex)
{ {

View file

@ -77,12 +77,24 @@ namespace UDPT
void Service::start() void Service::start()
{ {
std::shared_ptr<void> hSvc = getService(SERVICE_START);
BOOL bRes = ::StartService(reinterpret_cast<SC_HANDLE>(hSvc.get()), 0, NULL);
if (FALSE == bRes)
{
throw OSError();
}
} }
void Service::stop() void Service::stop()
{ {
SERVICE_STATUS status = { 0 };
std::shared_ptr<void> hSvc = getService(SERVICE_STOP);
BOOL bRes = ::ControlService(reinterpret_cast<SC_HANDLE>(hSvc.get()), SERVICE_CONTROL_STOP, &status);
if (FALSE == bRes)
{
throw OSError();
}
} }
void Service::setup() void Service::setup()