2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
19 * PROTOTYPES _________________________________________________________________
23 void Advanced_OnInitDialog (HWND hDlg);
24 void Advanced_StartTimer (HWND hDlg);
25 void Advanced_OnServiceTimer (HWND hDlg);
26 void Advanced_OnOpenCPL (HWND hDlg);
27 void Advanced_OnChangeService (HWND hDlg, WORD wCmd);
28 void Advanced_OnStartup (HWND hDlg);
32 * ROUTINES ___________________________________________________________________
36 BOOL CALLBACK Advanced_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
42 GetClientRect (GetParent(hDlg), &rTab);
43 TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab);
44 SetWindowPos (hDlg, NULL, rTab.left, rTab.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
46 Advanced_OnInitDialog (hDlg);
50 Advanced_OnServiceTimer (hDlg);
56 case IDC_SERVICE_STOP:
57 case IDC_SERVICE_START:
58 case IDC_SERVICE_AUTO:
59 Advanced_OnChangeService (hDlg, LOWORD(wp));
63 Advanced_OnOpenCPL (hDlg);
67 Advanced_OnStartup (hDlg);
71 Advanced_DlgProc (hDlg, WM_HELP, 0, 0);
77 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_TAB_ADVANCED);
84 void Advanced_OnInitDialog (HWND hDlg)
86 CheckDlgButton (hDlg, IDC_STARTUP, g.fStartup);
87 Advanced_OnServiceTimer (hDlg);
88 Advanced_StartTimer (hDlg);
92 void Advanced_StartTimer (HWND hDlg)
94 KillTimer (hDlg, ID_SERVICE_TIMER);
95 SetTimer (hDlg, ID_SERVICE_TIMER, (ULONG)cmsecSERVICE, NULL);
99 void Advanced_OnServiceTimer (HWND hDlg)
105 QUERY_SERVICE_CONFIG Config;
108 memset (&Config, 0x00, sizeof(Config));
109 Config.Config.dwStartType = SERVICE_DEMAND_START;
111 SERVICE_STATUS Status;
112 memset (&Status, 0x00, sizeof(Status));
113 Status.dwCurrentState = SERVICE_STOPPED;
116 if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
119 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
122 DWORD dwSize = sizeof(Config);
123 QueryServiceConfig (hService, (QUERY_SERVICE_CONFIG*)&Config, sizeof(Config), &dwSize);
124 QueryServiceStatus (hService, &Status);
125 TestAndDoMapShare(Status.dwCurrentState);
127 CloseServiceHandle (hService);
130 CloseServiceHandle (hManager);
135 if ((Status.dwCurrentState == SERVICE_STOP_PENDING) ||
136 (Status.dwCurrentState == SERVICE_START_PENDING))
142 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), fFound && (Status.dwCurrentState == SERVICE_STOPPED));
143 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP), fFound && (Status.dwCurrentState == SERVICE_RUNNING));
144 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_AUTO), fFound);
145 CheckDlgButton (hDlg, IDC_SERVICE_AUTO, fFound && (Config.Config.dwStartType == SERVICE_AUTO_START));
147 TCHAR szStatus[cchRESOURCE];
149 GetString (szStatus, IDS_SERVICE_BROKEN);
150 else if (Status.dwCurrentState == SERVICE_RUNNING)
151 GetString (szStatus, IDS_SERVICE_RUNNING);
152 else if (Status.dwCurrentState == SERVICE_STOPPED)
153 GetString (szStatus, IDS_SERVICE_STOPPED);
154 else if (Status.dwCurrentState == SERVICE_STOP_PENDING)
155 GetString (szStatus, IDS_SERVICE_STOPPING);
156 else if (Status.dwCurrentState == SERVICE_START_PENDING)
157 GetString (szStatus, IDS_SERVICE_STARTING);
159 GetString (szStatus, IDS_SERVICE_UNKNOWN);
160 TestAndDoMapShare(Status.dwCurrentState);
161 SetDlgItemText (hDlg, IDC_SERVICE_STATUS, szStatus);
163 if (fFinal && GetWindowLong (hDlg, DWL_USER))
165 SetWindowLong (hDlg, DWL_USER, 0);
166 Main_RepopulateTabs (FALSE);
171 KillTimer (hDlg, ID_SERVICE_TIMER);
176 void Advanced_OnChangeService (HWND hDlg, WORD wCmd)
178 BOOL fSuccess = FALSE;
180 SC_HANDLE hManager, hService;
184 case IDC_SERVICE_AUTO:
186 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
187 SC_MANAGER_ENUMERATE_SERVICE |
188 SC_MANAGER_QUERY_LOCK_STATUS)) != NULL)
190 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
191 SERVICE_CHANGE_CONFIG | SERVICE_QUERY_CONFIG |
192 SERVICE_QUERY_STATUS)) != NULL)
194 StartType = (IsDlgButtonChecked (hDlg, wCmd)) ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
195 if (ChangeServiceConfig (hService, SERVICE_NO_CHANGE, StartType,
196 SERVICE_NO_CHANGE, 0, 0, 0, 0, 0, 0, 0))
198 CloseServiceHandle (hService);
200 CloseServiceHandle (hManager);
204 case IDC_SERVICE_START:
205 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
206 SC_MANAGER_ENUMERATE_SERVICE |
207 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
209 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
210 SERVICE_QUERY_STATUS | SERVICE_START)) != NULL)
212 if (StartService (hService, 0, 0))
214 TestAndDoMapShare(SERVICE_START_PENDING);
217 CloseServiceHandle (hService);
219 CloseServiceHandle (hManager);
223 case IDC_SERVICE_STOP:
224 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
225 SC_MANAGER_ENUMERATE_SERVICE |
226 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
228 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
229 SERVICE_QUERY_STATUS | SERVICE_STOP)) != NULL)
231 SERVICE_STATUS Status;
232 TestAndDoUnMapShare();
233 ControlService (hService, SERVICE_CONTROL_STOP, &Status);
236 CloseServiceHandle (hService);
238 CloseServiceHandle (hManager);
244 if (wCmd == IDC_SERVICE_STOP)
245 SetWindowLong (hDlg, DWL_USER, TRUE);
246 Advanced_OnServiceTimer (hDlg);
247 Advanced_StartTimer (hDlg);
252 error = GetLastError();
257 case IDC_SERVICE_START:
258 ids = IDS_SERVICE_FAIL_START;
260 case IDC_SERVICE_STOP:
261 ids = IDS_SERVICE_FAIL_STOP;
264 ids = IDS_SERVICE_FAIL_CONFIG;
268 Message (MB_OK | MB_ICONHAND, IDS_SERVICE_ERROR, ids, TEXT("%08lX"), error);
273 void Advanced_OnOpenCPL (HWND hDlg)
275 WinExec ("afs_config.exe", SW_SHOW);
279 void Advanced_OnStartup (HWND hDlg)
281 g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP);
284 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
286 DWORD dwSize = sizeof(g.fStartup);
287 DWORD dwType = REG_DWORD;
288 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
292 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);