From 5ce1298452181eb6b569766a91fba30f1aff89e8 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Tue, 16 Feb 2016 15:49:13 -0500 Subject: [PATCH] Warn if interative service is not installed or not running Signed-off-by: Selva Nair --- main.c | 3 +++ openvpn-gui-res.h | 2 ++ res/openvpn-gui-res-en.rc | 4 ++++ service.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/main.c b/main.c index 20e81ab..b6b97be 100644 --- a/main.c +++ b/main.c @@ -178,6 +178,9 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, exit(1); } + if (!IsUserAdmin()) + CheckIServiceStatus(); + BuildFileList(); if (!VerifyAutoConnections()) { exit(1); diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index 2bf9d23..8a949ef 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -229,6 +229,8 @@ #define IDS_NFO_RESTARTED 1708 #define IDS_ERR_ACCESS_SERVICE_PIPE 1709 #define IDS_ERR_WRITE_SERVICE_PIPE 1710 +#define IDS_ERR_NOTSTARTED_ISERVICE 1711 +#define IDS_ERR_INSTALL_ISERVICE 1712 /* Registry Related */ #define IDS_ERR_GET_WINDOWS_DIR 1801 diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index 1b6ebb0..c994810 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -327,6 +327,10 @@ BEGIN IDS_NFO_RESTARTED "OpenVPN Service Restarted." IDS_ERR_ACCESS_SERVICE_PIPE "Access to service pipe failed." IDS_ERR_WRITE_SERVICE_PIPE "Writing to service pipe failed." + IDS_ERR_INSTALL_ISERVICE """OpenVPNServiceInteractive"" is not installed.\n" + "Tasks requiring administrative access may not work." + IDS_ERR_NOTSTARTED_ISERVICE """OpenVPNServiceInteractive"" is not started.\n" + "Tasks requiring administrative access may not work." /* registry */ IDS_ERR_GET_WINDOWS_DIR "Error getting Windows Directory." diff --git a/service.c b/service.c index 21cab44..fc7367f 100644 --- a/service.c +++ b/service.c @@ -241,6 +241,40 @@ int MyReStartService() return(false); } +bool +CheckIServiceStatus() +{ + SC_HANDLE schSCManager; + SC_HANDLE schService; + SERVICE_STATUS ssStatus; + + // Open a handle to the SC Manager database. + schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); + + if (NULL == schSCManager) + return(false); + + schService = OpenService(schSCManager, _T("OpenVPNServiceInteractive"), + SERVICE_QUERY_STATUS); + if (schService == NULL && + GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) + { + /* warn that iservice is not installed */ + ShowLocalizedMsg(IDS_ERR_INSTALL_ISERVICE); + return(false); + } + + if (!QueryServiceStatus(schService, &ssStatus)) + return(false); + + if (ssStatus.dwCurrentState != SERVICE_RUNNING) + { + /* warn that iservice is not started */ + ShowLocalizedMsg(IDS_ERR_NOTSTARTED_ISERVICE); + return(false); + } + return true; +} int CheckServiceStatus() {