diff --git a/main.c b/main.c index 29913b3..36bb4a4 100644 --- a/main.c +++ b/main.c @@ -487,7 +487,7 @@ HandleCopyDataMessage(const COPYDATASTRUCT *copy_data) static void CALLBACK ManagePersistent(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now) { - CheckServiceStatus(false); + CheckServiceStatus(); if (o.service_state == service_connected) { for (int i = 0; i < o.num_configs; i++) diff --git a/service.c b/service.c index 18cf870..60d5ca7 100644 --- a/service.c +++ b/service.c @@ -89,64 +89,60 @@ out: return ret; } -int CheckServiceStatus() +VOID CheckServiceStatus() { + SC_HANDLE schSCManager = NULL; + SC_HANDLE schService = NULL; + SERVICE_STATUS ssStatus; + + // Open a handle to the SC Manager database. + schSCManager = OpenSCManager( + NULL, // local machine + NULL, // ServicesActive database + SC_MANAGER_CONNECT); // Connect rights - SC_HANDLE schSCManager = NULL; - SC_HANDLE schService = NULL; - SERVICE_STATUS ssStatus; - BOOL ret = false; - - // Open a handle to the SC Manager database. - schSCManager = OpenSCManager( - NULL, // local machine - NULL, // ServicesActive database - SC_MANAGER_CONNECT); // Connect rights - if (NULL == schSCManager) { - o.service_state = service_noaccess; - goto out; + o.service_state = service_noaccess; + goto out; } - schService = OpenService( - schSCManager, // SCM database - _T("OpenVPNService"), // service name - SERVICE_QUERY_STATUS); - + schService = OpenService( + schSCManager, // SCM database + _T("OpenVPNService"), // service name + SERVICE_QUERY_STATUS); + if (schService == NULL) { - o.service_state = service_noaccess; - goto out; + o.service_state = service_noaccess; + goto out; } - if (!QueryServiceStatus( - schService, // handle to service + if (!QueryServiceStatus( + schService, // handle to service &ssStatus) ) // address of status information structure { - /* query failed */ - o.service_state = service_noaccess; - MsgToEventLog(EVENTLOG_ERROR_TYPE, LoadLocalizedString(IDS_ERR_QUERY_SERVICE)); - goto out; + /* query failed */ + o.service_state = service_noaccess; + MsgToEventLog(EVENTLOG_ERROR_TYPE, LoadLocalizedString(IDS_ERR_QUERY_SERVICE)); + goto out; } - - if (ssStatus.dwCurrentState == SERVICE_RUNNING) + + if (ssStatus.dwCurrentState == SERVICE_RUNNING) { o.service_state = service_connected; - ret = true; goto out; } - else - { + else + { o.service_state = service_disconnected; goto out; - } + } out: if (schService) CloseServiceHandle(schService); if (schSCManager) CloseServiceHandle(schSCManager); - return ret; -} +} /* Attempt to start OpenVPN Automatc Service */ void StartAutomaticService(void) diff --git a/service.h b/service.h index 70b8ed3..511017a 100644 --- a/service.h +++ b/service.h @@ -19,7 +19,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -int CheckServiceStatus(); +VOID CheckServiceStatus(); BOOL CheckIServiceStatus(BOOL warn); /* Attempt to start OpenVPN Automatc Service */ void StartAutomaticService(void);