29 #define WM_PH_CHILD_EXIT (WM_APP + 301)
80 static BOOLEAN PageInit;
81 static BOOLEAN PressedOk;
82 static BOOLEAN RestartRequired;
83 static POINT StartLocation;
84 static WNDPROC OldWndProc;
87 static HFONT CurrentFontInstance;
91 static PH_STRINGREF TaskMgrImageOptionsKeyName =
PH_STRINGREF_INIT(L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\taskmgr.exe");
93 static BOOLEAN OldReplaceTaskMgr;
94 static HWND WindowHandleForElevate;
97 static HWND HighlightingListViewHandle;
100 _In_ HWND ParentWindowHandle
103 PROPSHEETHEADER propSheetHeader = {
sizeof(propSheetHeader) };
104 PROPSHEETPAGE propSheetPage;
105 HPROPSHEETPAGE pages[5];
107 propSheetHeader.dwFlags =
113 propSheetHeader.hwndParent = ParentWindowHandle;
114 propSheetHeader.pszCaption = L
"Options";
115 propSheetHeader.nPages = 0;
117 propSheetHeader.phpage = pages;
124 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
125 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
128 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
132 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
133 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
136 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
141 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
142 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
145 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
151 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
152 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
155 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
161 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
162 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
165 pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
170 RestartRequired =
FALSE;
175 StartLocation.x = MINLONG;
177 OldTaskMgrDebugger = NULL;
179 PropertySheet(&propSheetHeader);
195 MB_ICONQUESTION | MB_YESNO,
196 L
"One or more options you have changed requires a restart of Process Hacker. "
197 L
"Do you want to restart Process Hacker now?"
231 case PSCB_BUTTONPRESSED:
233 if (lParam == PSBTN_OK)
244 static VOID PhpPageInit(
255 optionsWindow = GetParent(hwndDlg);
256 OldWndProc = (WNDPROC)GetWindowLongPtr(optionsWindow, GWLP_WNDPROC);
260 GetClientRect(optionsWindow, &clientRect);
261 GetWindowRect(GetDlgItem(optionsWindow, IDCANCEL), &rect);
262 MapWindowPoints(NULL, optionsWindow, (POINT *)&rect, 2);
263 resetButton = CreateWindowEx(
264 WS_EX_NOPARENTNOTIFY,
267 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
268 clientRect.right - rect.right,
270 rect.right - rect.left,
271 rect.bottom - rect.top,
277 SendMessage(resetButton, WM_SETFONT, SendMessage(GetDlgItem(optionsWindow, IDCANCEL), WM_GETFONT, 0, 0),
TRUE);
280 ShowWindow(resetButton, SW_HIDE);
283 if (StartLocation.x == MINLONG)
289 SetWindowPos(optionsWindow, NULL, StartLocation.x, StartLocation.y, 0, 0,
290 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER);
293 SetWindowText(optionsWindow, L
"Options");
310 switch (LOWORD(wParam))
316 MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2,
317 L
"Do you want to reset all settings and restart Process Hacker?"
345 return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam);
348 #define SetDlgItemCheckForSetting(hwndDlg, Id, Name) \
349 Button_SetCheck(GetDlgItem(hwndDlg, Id), PhGetIntegerSetting(Name) ? BST_CHECKED : BST_UNCHECKED)
350 #define SetSettingForDlgItemCheck(hwndDlg, Id, Name) \
351 PhSetIntegerSetting(Name, Button_GetCheck(GetDlgItem(hwndDlg, Id)) == BST_CHECKED)
352 #define SetSettingForDlgItemCheckRestartRequired(hwndDlg, Id, Name) \
354 BOOLEAN __oldValue = !!PhGetIntegerSetting(Name); \
355 BOOLEAN __newValue = Button_GetCheck(GetDlgItem(hwndDlg, Id)) == BST_CHECKED; \
356 if (__newValue != __oldValue) \
357 RestartRequired = TRUE; \
358 PhSetIntegerSetting(Name, __newValue); \
360 #define DialogChanged PropSheet_Changed(GetParent(hwndDlg), hwndDlg)
362 static BOOLEAN GetCurrentFont(
369 if (NewFontSelection)
374 if (fontHexString->
Length / 2 / 2 ==
sizeof(LOGFONT))
399 PhpPageInit(hwndDlg);
412 ComboBox_SetCurSel(comboBoxHandle,
sizeof(
PhSizeUnitNames) /
sizeof(PWSTR) - 1);
426 if (GetCurrentFont(&font))
428 CurrentFontInstance = CreateFontIndirect(&font);
430 if (CurrentFontInstance)
431 SendMessage(GetDlgItem(hwndDlg,
IDC_FONT), WM_SETFONT, (WPARAM)CurrentFontInstance,
TRUE);
437 if (CurrentFontInstance)
438 DeleteObject(CurrentFontInstance);
445 switch (LOWORD(wParam))
450 CHOOSEFONT chooseFont;
452 if (!GetCurrentFont(&font))
460 memset(&chooseFont, 0,
sizeof(CHOOSEFONT));
461 chooseFont.lStructSize =
sizeof(CHOOSEFONT);
462 chooseFont.hwndOwner = hwndDlg;
463 chooseFont.lpLogFont = &font;
464 chooseFont.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
466 if (ChooseFont(&chooseFont))
472 if (CurrentFontInstance)
473 DeleteObject(CurrentFontInstance);
475 CurrentFontInstance = CreateFontIndirect(&font);
476 SendMessage(GetDlgItem(hwndDlg,
IDC_FONT), WM_SETFONT, (WPARAM)CurrentFontInstance,
TRUE);
485 LPNMHDR header = (LPNMHDR)lParam;
487 switch (header->code)
504 if (NewFontSelection)
510 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
521 static BOOLEAN PathMatchesPh(
525 BOOLEAN match =
FALSE;
534 OldTaskMgrDebugger->
Buffer[0] ==
'"' &&
535 OldTaskMgrDebugger->
Buffer[OldTaskMgrDebugger->
Length / 2 - 1] ==
'"'
541 partInside.
Length = OldTaskMgrDebugger->
Length -
sizeof(WCHAR) * 2;
575 changeButton = GetDlgItem(hwndDlg,
IDC_CHANGE);
579 ShowWindow(changeButton, SW_HIDE);
583 SendMessage(changeButton, BCM_SETSHIELD, 0,
TRUE);
587 HANDLE taskmgrKeyHandle = NULL;
589 BOOLEAN success =
FALSE;
590 BOOLEAN alreadyReplaced =
FALSE;
595 KEY_READ | KEY_WRITE,
597 &TaskMgrImageOptionsKeyName,
610 &TaskMgrImageOptionsKeyName,
614 if (OldTaskMgrDebugger)
619 alreadyReplaced = PathMatchesPh(OldTaskMgrDebugger);
622 NtClose(taskmgrKeyHandle);
628 OldReplaceTaskMgr = alreadyReplaced;
629 Button_SetCheck(GetDlgItem(hwndDlg,
IDC_REPLACETASKMANAGER), alreadyReplaced ? BST_CHECKED : BST_UNCHECKED);
653 if (sampleCount == 0)
657 RestartRequired =
TRUE;
665 HANDLE taskmgrKeyHandle;
666 BOOLEAN replaceTaskMgr;
671 if (OldReplaceTaskMgr != replaceTaskMgr)
679 &TaskMgrImageOptionsKeyName,
690 status =
NtSetValueKey(taskmgrKeyHandle, &valueName, 0, REG_SZ, quotedFileName->
Buffer, (ULONG)quotedFileName->
Length + 2);
699 PhShowStatus(hwndDlg, L
"Unable to replace Task Manager", status, 0);
701 NtClose(taskmgrKeyHandle);
713 arguments = Parameter;
715 WindowHandleForElevate,
727 return STATUS_SUCCESS;
741 PhpPageInit(hwndDlg);
768 if (OldTaskMgrDebugger)
774 switch (LOWORD(wParam))
785 GetWindowRect(GetParent(hwndDlg), &windowRect);
786 WindowHandleForElevate = hwndDlg;
788 L
"-showoptions -hwnd %Ix -point %u,%u",
789 (ULONG_PTR)GetParent(hwndDlg),
790 windowRect.left + 20,
795 NtClose(threadHandle);
808 LPNMHDR header = (LPNMHDR)lParam;
810 switch (header->code)
815 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
842 PhpPageInit(hwndDlg);
852 switch (LOWORD(wParam))
858 { L
"dbghelp.dll", L
"dbghelp.dll" },
859 { L
"All files (*.*)", L
"*.*" }
886 LPNMHDR header = (LPNMHDR)lParam;
888 switch (header->code)
899 RestartRequired =
TRUE;
905 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
916 #define CROSS_INDEX 0
919 typedef struct _COLOR_ITEM
922 PWSTR UseSettingName;
927 COLORREF CurrentColor;
930 #define COLOR_ITEM(SettingName, Name, Description) { SettingName, L"Use" SettingName, Name, Description }
934 COLOR_ITEM(L
"ColorOwnProcesses", L
"Own Processes", L
"Processes running under the same user account as Process Hacker."),
935 COLOR_ITEM(L
"ColorSystemProcesses", L
"System Processes", L
"Processes running under the NT AUTHORITY\\SYSTEM user account."),
936 COLOR_ITEM(L
"ColorServiceProcesses", L
"Service Processes", L
"Processes which host one or more services."),
937 COLOR_ITEM(L
"ColorJobProcesses", L
"Job Processes", L
"Processes associated with a job."),
939 COLOR_ITEM(L
"ColorWow64Processes", L
"32-bit Processes", L
"Processes running under WOW64, i.e. 32-bit."),
941 COLOR_ITEM(L
"ColorPosixProcesses", L
"POSIX Processes", L
"Processes running under the POSIX subsystem."),
942 COLOR_ITEM(L
"ColorDebuggedProcesses", L
"Debugged Processes", L
"Processes that are currently being debugged."),
943 COLOR_ITEM(L
"ColorElevatedProcesses", L
"Elevated Processes", L
"Processes with full privileges on a system with UAC enabled."),
944 COLOR_ITEM(L
"ColorImmersiveProcesses", L
"Immersive Processes and DLLs", L
"Processes and DLLs that belong to a Modern UI app."),
945 COLOR_ITEM(L
"ColorSuspended", L
"Suspended Processes and Threads", L
"Processes and threads that are suspended from execution."),
946 COLOR_ITEM(L
"ColorDotNet", L
".NET Processes and DLLs", L
".NET (i.e. managed) processes and DLLs."),
947 COLOR_ITEM(L
"ColorPacked", L
"Packed Processes", L
"Executables are sometimes \"packed\" to reduce their size."),
948 COLOR_ITEM(L
"ColorGuiThreads", L
"GUI Threads", L
"Threads that have made at least one GUI-related system call."),
949 COLOR_ITEM(L
"ColorRelocatedModules", L
"Relocated DLLs", L
"DLLs that were not loaded at their preferred image bases."),
950 COLOR_ITEM(L
"ColorProtectedHandles", L
"Protected Handles", L
"Handles that are protected from being closed."),
951 COLOR_ITEM(L
"ColorInheritHandles", L
"Inheritable Handles", L
"Handles that can be inherited by child processes.")
957 _In_opt_ PVOID Context
960 PCOLOR_ITEM item = Param;
962 return item->CurrentColor;
978 PhpPageInit(hwndDlg);
990 HighlightingListViewHandle = GetDlgItem(hwndDlg,
IDC_LIST);
992 ListView_SetExtendedListViewStyleEx(HighlightingListViewHandle, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
997 for (i = 0; i <
sizeof(ColorItems) /
sizeof(
COLOR_ITEM); i++)
1001 lvItemIndex =
PhAddListViewItem(HighlightingListViewHandle, MAXINT, ColorItems[i].Name, &ColorItems[i]);
1004 ListView_SetCheckState(HighlightingListViewHandle, lvItemIndex, ColorItems[i].CurrentUse);
1012 switch (LOWORD(wParam))
1018 for (i = 0; i <
sizeof(ColorItems) /
sizeof(
COLOR_ITEM); i++)
1019 ListView_SetCheckState(HighlightingListViewHandle, i,
TRUE);
1026 for (i = 0; i <
sizeof(ColorItems) /
sizeof(
COLOR_ITEM); i++)
1027 ListView_SetCheckState(HighlightingListViewHandle, i,
FALSE);
1035 LPNMHDR header = (LPNMHDR)lParam;
1037 switch (header->code)
1047 for (i = 0; i <
sizeof(ColorItems) /
sizeof(
COLOR_ITEM); i++)
1049 ColorItems[i].CurrentUse = !!ListView_GetCheckState(HighlightingListViewHandle, i);
1054 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1059 if (header->hwndFrom == HighlightingListViewHandle)
1065 CHOOSECOLOR chooseColor = {
sizeof(chooseColor) };
1066 COLORREF customColors[16] = { 0 };
1068 chooseColor.hwndOwner = hwndDlg;
1069 chooseColor.rgbResult = item->CurrentColor;
1070 chooseColor.lpCustColors = customColors;
1071 chooseColor.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
1073 if (ChooseColor(&chooseColor))
1075 item->CurrentColor = chooseColor.rgbResult;
1076 InvalidateRect(HighlightingListViewHandle, NULL,
TRUE);
1082 case LVN_GETINFOTIP:
1084 if (header->hwndFrom == HighlightingListViewHandle)
1086 NMLVGETINFOTIP *getInfoTip = (NMLVGETINFOTIP *)lParam;
1115 PhpPageInit(hwndDlg);
1132 LPNMHDR header = (LPNMHDR)lParam;
1134 switch (header->code)
1148 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);