2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/propsheet_logon.c
5 * PURPOSE: Logon property page
14 #define DEFAULT_PASSWORD L" "
16 typedef struct _LOGONDATA
18 ENUM_SERVICE_STATUS_PROCESS
*pService
;
19 LPQUERY_SERVICE_CONFIG pServiceConfig
;
20 WCHAR szAccountName
[64];
21 WCHAR szPassword1
[64];
22 WCHAR szPassword2
[64];
27 } LOGONDATA
, *PLOGONDATA
;
34 PLOGONDATA pLogonData
,
37 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_INTERACTIVE
), bLocalSystem
);
38 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_ACCOUNTNAME
), !bLocalSystem
);
39 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_SEARCH
), FALSE
/*!bLocalSystem*/);
40 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_PW1TEXT
), !bLocalSystem
);
41 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_PASSWORD1
), !bLocalSystem
);
42 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_PW2TEXT
), !bLocalSystem
);
43 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_PASSWORD2
), !bLocalSystem
);
47 SendDlgItemMessageW(hwndDlg
, IDC_LOGON_INTERACTIVE
, BM_SETCHECK
, (WPARAM
)pLogonData
->nInteractive
, 0);
49 if (pLogonData
->bInitialized
== TRUE
)
51 GetDlgItemText(hwndDlg
, IDC_LOGON_ACCOUNTNAME
, pLogonData
->szAccountName
, 64);
52 GetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD1
, pLogonData
->szPassword1
, 64);
53 GetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD2
, pLogonData
->szPassword2
, 64);
56 SetDlgItemText(hwndDlg
, IDC_LOGON_ACCOUNTNAME
, L
"");
57 SetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD1
, L
"");
58 SetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD2
, L
"");
62 if (pLogonData
->bInitialized
== TRUE
)
63 pLogonData
->nInteractive
= SendDlgItemMessageW(hwndDlg
, IDC_LOGON_INTERACTIVE
, BM_GETCHECK
, 0, 0);
64 SendDlgItemMessageW(hwndDlg
, IDC_LOGON_INTERACTIVE
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
66 SetDlgItemText(hwndDlg
, IDC_LOGON_ACCOUNTNAME
, pLogonData
->szAccountName
);
67 SetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD1
, pLogonData
->szPassword1
);
68 SetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD2
, pLogonData
->szPassword2
);
71 pLogonData
->bLocalSystem
= bLocalSystem
;
88 hSCManager
= OpenSCManagerW(NULL
,
93 scLock
= LockServiceDatabase(hSCManager
);
96 hSc
= OpenServiceW(hSCManager
,
98 SERVICE_CHANGE_CONFIG
);
101 if (ChangeServiceConfigW(hSc
,
116 CloseServiceHandle(hSc
);
119 UnlockServiceDatabase(scLock
);
122 CloseServiceHandle(hSCManager
);
136 PLOGONDATA pLogonData
)
138 HWND hwnd
= GetDlgItem(hwndDlg
, pLogonData
->bLocalSystem
? IDC_LOGON_SYSTEMACCOUNT
: IDC_LOGON_THISACCOUNT
);
140 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, (LPARAM
)hwnd
);
150 PLOGONDATA pLogonData
)
152 WCHAR szAccountName
[64];
153 WCHAR szPassword1
[64];
154 WCHAR szPassword2
[64];
155 DWORD dwServiceType
= SERVICE_NO_CHANGE
;
158 if (!pLogonData
->bAccountChanged
)
161 if (SendDlgItemMessageW(hwndDlg
, IDC_LOGON_SYSTEMACCOUNT
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
163 /* System account selected */
164 wcscpy(szAccountName
, L
"LocalSystem");
165 wcscpy(szPassword1
, L
"");
166 wcscpy(szPassword2
, L
"");
168 /* Handle the interactive flag */
169 dwServiceType
= pLogonData
->pServiceConfig
->dwServiceType
;
170 if (SendDlgItemMessageW(hwndDlg
, IDC_LOGON_INTERACTIVE
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
171 dwServiceType
|= SERVICE_INTERACTIVE_PROCESS
;
173 dwServiceType
&= ~SERVICE_INTERACTIVE_PROCESS
;
177 /* Other account selected */
178 GetDlgItemText(hwndDlg
, IDC_LOGON_ACCOUNTNAME
, szAccountName
, 64);
179 GetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD1
, szPassword1
, 64);
180 GetDlgItemText(hwndDlg
, IDC_LOGON_PASSWORD2
, szPassword2
, 64);
182 if (wcscmp(szPassword1
, szPassword2
))
184 ResourceMessageBox(GetModuleHandle(NULL
), hwndDlg
, MB_OK
| MB_ICONWARNING
, IDS_APPNAME
, IDS_NOT_SAME_PASSWORD
);
188 if (!wcscmp(szPassword1
, DEFAULT_PASSWORD
))
190 ResourceMessageBox(GetModuleHandle(NULL
), hwndDlg
, MB_OK
| MB_ICONWARNING
, IDS_APPNAME
, IDS_INVALID_PASSWORD
);
196 bRet
= SetServiceAccount(pLogonData
->pService
->lpServiceName
,
207 pLogonData
->bAccountChanged
= FALSE
;
216 * Logon Property dialog callback.
217 * Controls messages to the Logon dialog
227 PLOGONDATA pLogonData
;
229 /* Get the window context */
230 pLogonData
= (PLOGONDATA
)GetWindowLongPtr(hwndDlg
,
232 if (pLogonData
== NULL
&& uMsg
!= WM_INITDIALOG
)
240 pLogonData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LOGONDATA
));
241 if (pLogonData
!= NULL
)
243 SetWindowLongPtr(hwndDlg
,
245 (LONG_PTR
)pLogonData
);
247 pLogonData
->bInitialized
= FALSE
;
248 pLogonData
->pService
= ((PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
))->pService
;
250 pLogonData
->pServiceConfig
= GetServiceConfig(pLogonData
->pService
->lpServiceName
);
251 if (pLogonData
->pServiceConfig
!= NULL
)
253 wcscpy(pLogonData
->szPassword1
, DEFAULT_PASSWORD
);
254 wcscpy(pLogonData
->szPassword2
, DEFAULT_PASSWORD
);
256 if (pLogonData
->pServiceConfig
->lpServiceStartName
== NULL
||
257 _wcsicmp(pLogonData
->pServiceConfig
->lpServiceStartName
, L
"LocalSystem") == 0)
259 SendDlgItemMessageW(hwndDlg
, IDC_LOGON_SYSTEMACCOUNT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
260 if (pLogonData
->pServiceConfig
->dwServiceType
& SERVICE_INTERACTIVE_PROCESS
) {
261 pLogonData
->nInteractive
= BST_CHECKED
;
262 SendDlgItemMessageW(hwndDlg
, IDC_LOGON_INTERACTIVE
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
264 SetControlStates(hwndDlg
, pLogonData
, TRUE
);
268 wcscpy(pLogonData
->szAccountName
, pLogonData
->pServiceConfig
->lpServiceStartName
);
269 SendDlgItemMessageW(hwndDlg
, IDC_LOGON_THISACCOUNT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
270 SetControlStates(hwndDlg
, pLogonData
, FALSE
);
274 pLogonData
->bInitialized
= TRUE
;
277 EnableWindow(GetDlgItem(hwndDlg
, IDC_LOGON_HWPROFILE
), FALSE
);
281 if (pLogonData
->pServiceConfig
)
282 HeapFree(GetProcessHeap(), 0, pLogonData
->pServiceConfig
);
284 HeapFree(GetProcessHeap(), 0, pLogonData
);
288 switch(LOWORD(wParam
))
290 case IDC_LOGON_SYSTEMACCOUNT
:
291 if (HIWORD(wParam
) == BN_CLICKED
)
293 if (pLogonData
->bInitialized
)
295 pLogonData
->bAccountChanged
= TRUE
;
296 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
298 SetControlStates(hwndDlg
, pLogonData
, TRUE
);
302 case IDC_LOGON_THISACCOUNT
:
303 if (HIWORD(wParam
) == BN_CLICKED
)
305 if (pLogonData
->bInitialized
)
307 pLogonData
->bAccountChanged
= TRUE
;
308 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
310 SetControlStates(hwndDlg
, pLogonData
, FALSE
);
314 case IDC_LOGON_INTERACTIVE
:
315 if (HIWORD(wParam
) == BN_CLICKED
)
317 if (pLogonData
->bInitialized
)
319 pLogonData
->bAccountChanged
= TRUE
;
320 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
325 case IDC_LOGON_ACCOUNTNAME
:
326 case IDC_LOGON_PASSWORD1
:
327 case IDC_LOGON_PASSWORD2
:
328 if (HIWORD(wParam
) == EN_CHANGE
&& pLogonData
->bInitialized
)
330 pLogonData
->bAccountChanged
= TRUE
;
331 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
338 switch (((LPNMHDR
)lParam
)->code
)
340 case PSN_QUERYINITIALFOCUS
:
341 return OnQueryInitialFocus(hwndDlg
, pLogonData
);
344 return OnApply(hwndDlg
, pLogonData
);