diff --git a/src/main.cpp b/src/main.cpp index cdebc42..2aa342e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -182,6 +182,11 @@ int main(int argc, char *argv[]) { svc.stop(); } + else + { + std::cerr << "No such service command." << std::endl; + return -1; + } } catch (const UDPT::OSError& ex) { diff --git a/src/service.cpp b/src/service.cpp index 9c146c2..d61aacf 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -77,12 +77,24 @@ namespace UDPT void Service::start() { - + std::shared_ptr hSvc = getService(SERVICE_START); + BOOL bRes = ::StartService(reinterpret_cast(hSvc.get()), 0, NULL); + if (FALSE == bRes) + { + throw OSError(); + } } void Service::stop() { + SERVICE_STATUS status = { 0 }; + std::shared_ptr hSvc = getService(SERVICE_STOP); + BOOL bRes = ::ControlService(reinterpret_cast(hSvc.get()), SERVICE_CONTROL_STOP, &status); + if (FALSE == bRes) + { + throw OSError(); + } } void Service::setup()