@ -89,49 +89,46 @@ out:
return ret ;
return ret ;
}
}
int CheckServiceStatus ( )
VOID CheckServiceStatus ( )
{
{
SC_HANDLE schSCManager = NULL ;
SC_HANDLE schSCManager = NULL ;
SC_HANDLE schService = NULL ;
SC_HANDLE schService = NULL ;
SERVICE_STATUS ssStatus ;
SERVICE_STATUS ssStatus ;
BOOL ret = false ;
// Open a handle to the SC Manager database.
// Open a handle to the SC Manager database.
schSCManager = OpenSCManager (
schSCManager = OpenSCManager (
NULL , // local machine
NULL , // local machine
NULL , // ServicesActive database
NULL , // ServicesActive database
SC_MANAGER_CONNECT ) ; // Connect rights
SC_MANAGER_CONNECT ) ; // Connect rights
if ( NULL = = schSCManager ) {
if ( NULL = = schSCManager ) {
o . service_state = service_noaccess ;
o . service_state = service_noaccess ;
goto out ;
goto out ;
}
}
schService = OpenService (
schService = OpenService (
schSCManager , // SCM database
schSCManager , // SCM database
_T ( " OpenVPNService " ) , // service name
_T ( " OpenVPNService " ) , // service name
SERVICE_QUERY_STATUS ) ;
SERVICE_QUERY_STATUS ) ;
if ( schService = = NULL ) {
if ( schService = = NULL ) {
o . service_state = service_noaccess ;
o . service_state = service_noaccess ;
goto out ;
goto out ;
}
}
if ( ! QueryServiceStatus (
if ( ! QueryServiceStatus (
schService , // handle to service
schService , // handle to service
& ssStatus ) ) // address of status information structure
& ssStatus ) ) // address of status information structure
{
{
/* query failed */
/* query failed */
o . service_state = service_noaccess ;
o . service_state = service_noaccess ;
MsgToEventLog ( EVENTLOG_ERROR_TYPE , LoadLocalizedString ( IDS_ERR_QUERY_SERVICE ) ) ;
MsgToEventLog ( EVENTLOG_ERROR_TYPE , LoadLocalizedString ( IDS_ERR_QUERY_SERVICE ) ) ;
goto out ;
goto out ;
}
}
if ( ssStatus . dwCurrentState = = SERVICE_RUNNING )
if ( ssStatus . dwCurrentState = = SERVICE_RUNNING )
{
{
o . service_state = service_connected ;
o . service_state = service_connected ;
ret = true ;
goto out ;
goto out ;
}
}
else
else
@ -145,7 +142,6 @@ out:
CloseServiceHandle ( schService ) ;
CloseServiceHandle ( schService ) ;
if ( schSCManager )
if ( schSCManager )
CloseServiceHandle ( schSCManager ) ;
CloseServiceHandle ( schSCManager ) ;
return ret ;
}
}
/* Attempt to start OpenVPN Automatc Service */
/* Attempt to start OpenVPN Automatc Service */