BOOL Config_ContactGateway (LPTSTR pszGateway, LPTSTR pszCell) { BOOL rc = FALSE; BYTE OutData[ PIOCTL_MAXSIZE ]; memset (OutData, 0x00, sizeof(OutData)); struct ViceIoctl IOInfo; IOInfo.in_size = 0; IOInfo.in = 0; IOInfo.out = (char *)OutData; IOInfo.out_size = PIOCTL_MAXSIZE; TCHAR szOldGateway[ MAX_PATH ]; Config_GetGatewayName (szOldGateway); Config_SetGatewayName (pszGateway); ULONG status; if ((status = pioctl (0, VIOC_GET_WS_CELL, &IOInfo, 1)) == 0) { if (OutData[0]) { lstrcpy (pszCell, (LPCTSTR)OutData); rc = TRUE; } } Config_SetGatewayName (szOldGateway); return rc; }
DWORD Config_GetServiceState (void) { if (!g.fIsWinNT) { TCHAR szGateway[ cchRESOURCE ] = TEXT(""); Config_GetGatewayName (szGateway); return (szGateway[0]) ? SERVICE_RUNNING : SERVICE_STOPPED; } SERVICE_STATUS Status; memset (&Status, 0x00, sizeof(Status)); SC_HANDLE hManager; if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL) { SC_HANDLE hService; if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL) { QueryServiceStatus (hService, &Status); CloseServiceHandle (hService); } CloseServiceHandle (hManager); } return Status.dwCurrentState; }
void GeneralTab_OnRefresh (HWND hDlg, BOOL fRequery) { // If necessary, update any fields in g.Configuration that we care about // if (fRequery) { if (g.fIsWinNT) Config_GetGatewayFlag (&g.Configuration.fBeGateway); else Config_GetGatewayName (g.Configuration.szGateway); Config_GetCellName (g.Configuration.szCell); g.Configuration.fLogonAuthent=RWLogonOption(TRUE,LOGON_OPTION_INTEGRATED); Config_GetTrayIconFlag (&g.Configuration.fShowTrayIcon); if (!g.fIsWinNT) SetDlgItemText (hDlg, IDC_GATEWAY, g.Configuration.szGateway); else CheckDlgButton (hDlg, IDC_GATEWAY, g.Configuration.fBeGateway); SetDlgItemText (hDlg, IDC_CELL, g.Configuration.szCell); CheckDlgButton (hDlg, IDC_LOGON, g.Configuration.fLogonAuthent); CheckDlgButton (hDlg, IDC_TRAYICON, g.Configuration.fShowTrayIcon); } // Update our display of the service's status // DWORD CurrentState = Config_GetServiceState(); BOOL fIfServiceStopped = !(g.fIsWinNT && !g.fIsAdmin); BOOL fIfServiceRunning = fIfServiceStopped && (CurrentState == SERVICE_RUNNING); GeneralTab_ShowCurrentState (hDlg); EnableWindow (GetDlgItem (hDlg, IDC_CELL), fIfServiceStopped && g.fIsWinNT); EnableWindow (GetDlgItem (hDlg, IDC_LOGON), fIfServiceStopped); EnableWindow (GetDlgItem (hDlg, IDC_GATEWAY), fIfServiceStopped); // Update our warning. Note that under WinNT, this tab doesn't have any // controls (other than Start Service) which disable just because the // service isn't running...so don't show that warning in that case. // TCHAR szText[ cchRESOURCE ]; if ((!g.fIsWinNT) && (CurrentState != SERVICE_RUNNING)) { GetString (szText, IDS_WARN_STOPPED); SetDlgItemText (hDlg, IDC_WARN, szText); ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW); } else if (g.fIsWinNT && !g.fIsAdmin) { GetString (szText, IDS_WARN_ADMIN); SetDlgItemText (hDlg, IDC_WARN, szText); ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW); } else // ((CurrentState == SERVICE_RUNNING) && (g.fIsAdmin)) { ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_HIDE); } GeneralTab_OnGateway (hDlg); // If the service isn't running/stopped, we may need to complain // if ((CurrentState == SERVICE_RUNNING) && (l.fWarnIfNotStopped)) { Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_STOP, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR); } else if ((CurrentState == SERVICE_STOPPED) && (l.fWarnIfStopped)) { Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_START, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR); } if ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED)) { BOOL fRestart = ((CurrentState == SERVICE_STOPPED) && (l.fRestartIfStopped)); l.fWarnIfStopped = FALSE; l.fWarnIfNotStopped = FALSE; l.fRestartIfStopped = FALSE; l.fServiceIsRunning = (CurrentState == SERVICE_RUNNING); if (fRestart) { GeneralTab_DoStartStop (hDlg, TRUE, FALSE); } } }