29 typedef struct _SERVICE_PROPERTIES_CONTEXT
35 BOOLEAN OldDelayedStart;
45 static NTSTATUS PhpOpenService(
47 _In_ ACCESS_MASK DesiredAccess,
48 _In_opt_ PVOID Context
51 SC_HANDLE serviceHandle;
59 *Handle = serviceHandle;
61 return STATUS_SUCCESS;
64 static _Callback_ NTSTATUS PhpSetServiceSecurity(
65 _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
66 _In_ SECURITY_INFORMATION SecurityInformation,
67 _In_opt_ PVOID Context
77 if ((status == STATUS_ACCESS_DENIED || status == NTSTATUS_FROM_WIN32(ERROR_ACCESS_DENIED)) && !
PhElevated)
95 _In_ HWND ParentWindowHandle,
99 PROPSHEETHEADER propSheetHeader = {
sizeof(propSheetHeader) };
100 PROPSHEETPAGE propSheetPage;
101 HPROPSHEETPAGE pages[32];
105 ULONG numberOfAccessEntries;
107 propSheetHeader.dwFlags =
111 propSheetHeader.hwndParent = ParentWindowHandle;
112 propSheetHeader.pszCaption = ServiceItem->
Name->Buffer;
113 propSheetHeader.nPages = 0;
114 propSheetHeader.nStartPage = 0;
115 propSheetHeader.phpage = pages;
120 context.ServiceItem = ServiceItem;
121 context.Ready =
FALSE;
122 context.Dirty =
FALSE;
124 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
125 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
128 propSheetPage.lParam = (LPARAM)&context;
129 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
133 stdObjectSecurity.
OpenObject = PhpOpenService;
135 stdObjectSecurity.
Context = ServiceItem;
140 ServiceItem->Name->Buffer,
142 PhpSetServiceSecurity,
145 numberOfAccessEntries
154 objectProperties.
Parameter = ServiceItem;
157 objectProperties.
Pages = pages;
164 PropertySheet(&propSheetHeader);
167 static VOID PhpRefreshControls(
195 LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
198 SC_HANDLE serviceHandle;
204 PhCenterWindow(GetParent(hwndDlg), GetParent(GetParent(hwndDlg)));
215 SetDlgItemText(hwndDlg,
IDC_DESCRIPTION, serviceItem->DisplayName->Buffer);
219 startType = serviceItem->StartType;
220 errorControl = serviceItem->ErrorControl;
221 serviceHandle =
PhOpenService(serviceItem->Name->Buffer, SERVICE_QUERY_CONFIG);
225 LPQUERY_SERVICE_CONFIG config;
227 BOOLEAN delayedStart;
231 SetDlgItemText(hwndDlg,
IDC_GROUP, config->lpLoadOrderGroup);
232 SetDlgItemText(hwndDlg,
IDC_BINARYPATH, config->lpBinaryPathName);
235 if (startType != config->dwStartType || errorControl != config->dwErrorControl)
237 startType = config->dwStartType;
238 errorControl = config->dwErrorControl;
256 context->OldDelayedStart = delayedStart;
262 CloseServiceHandle(serviceHandle);
283 PhpRefreshControls(hwndDlg);
285 context->Ready =
TRUE;
298 switch (LOWORD(wParam))
304 SendMessage(GetParent(hwndDlg), uMsg, wParam, lParam);
309 if (HIWORD(wParam) == EN_CHANGE)
317 context->Dirty =
TRUE;
324 { L
"Executable files (*.exe;*.sys)", L
"*.exe;*.sys" },
325 { L
"All files (*.*)", L
"*.*" }
336 if (context->ServiceItem->Type & SERVICE_WIN32)
367 switch (HIWORD(wParam))
372 PhpRefreshControls(hwndDlg);
375 context->Dirty =
TRUE;
383 LPNMHDR header = (LPNMHDR)lParam;
385 switch (header->code)
387 case PSN_QUERYINITIALFOCUS:
389 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)GetDlgItem(hwndDlg,
IDC_STARTTYPE));
394 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
FALSE);
403 SC_HANDLE serviceHandle;
407 ULONG newServiceType;
408 ULONG newServiceStartType;
409 ULONG newServiceErrorControl;
415 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
439 newServicePassword = NULL;
442 if (newServiceType == SERVICE_KERNEL_DRIVER && newServiceUserAccount->
Length == 0)
444 newServiceUserAccount = NULL;
451 if (ChangeServiceConfig(
455 newServiceErrorControl,
456 newServiceBinaryPath->
Buffer,
467 BOOLEAN newDelayedStart;
469 newDelayedStart = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_DELAYEDSTART)) == BST_CHECKED;
471 if (newDelayedStart != context->OldDelayedStart)
479 CloseServiceHandle(serviceHandle);
483 CloseServiceHandle(serviceHandle);
489 if (GetLastError() == ERROR_ACCESS_DENIED && !
PhElevated)
498 newServiceErrorControl,
499 newServiceBinaryPath->
Buffer,
510 BOOLEAN newDelayedStart;
512 newDelayedStart = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_DELAYEDSTART)) == BST_CHECKED;
514 if (newDelayedStart != context->OldDelayedStart)
516 SERVICE_DELAYED_AUTO_START_INFO info;
518 info.fDelayedAutostart = newDelayedStart;
521 SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
541 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
554 MB_ICONERROR | MB_RETRYCANCEL,
555 L
"Unable to change service configuration: %s",
559 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
563 if (newServicePassword)
565 RtlSecureZeroMemory(newServicePassword->
Buffer, newServicePassword->
Length);