84 _In_ HINSTANCE hInstance,
85 _In_opt_ HINSTANCE hPrevInstance,
92 PHP_BASE_THREAD_DBG dbg;
95 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
96 SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
109 PTOKEN_USER tokenUser;
121 if (!PhLocalSystemName)
128 if (!PhApplicationFileName)
130 if (!PhApplicationDirectory)
149 !PhStartupParameters.
PhSvc)
165 PhShowStatus(NULL, L
"Unable to execute the command", status, 0);
172 dbg.ClientId = NtCurrentTeb()->ClientId;
174 dbg.Parameter = NULL;
176 TlsSetValue(PhDbgThreadDbgTlsIndex, &dbg);
188 PhSmallIconSize.
X = GetSystemMetrics(SM_CXSMICON);
189 PhSmallIconSize.
Y = GetSystemMetrics(SM_CYSMICON);
190 PhLargeIconSize.
X = GetSystemMetrics(SM_CXICON);
191 PhLargeIconSize.
Y = GetSystemMetrics(SM_CYICON);
204 L
"You are attempting to run the 32-bit version of Process Hacker on 64-bit Windows. "
205 L
"Most features will not work correctly.\n\n"
206 L
"Please run the 64-bit version of Process Hacker instead."
218 if (PhStartupParameters.
PhSvc)
223 PostMessage(NULL, WM_NULL, 0, 0);
224 GetMessage(&message, NULL, 0, 0);
244 NtCreateMutant(&mutantHandle, MUTANT_ALL_ACCESS, &oa,
FALSE);
257 NtSetInformationProcess(NtCurrentProcess(), ProcessPriorityClass, &priorityClass,
sizeof(
PROCESS_PRIORITY_CLASS));
262 PhShowError(NULL, L
"Unable to initialize the main window.");
278 HACCEL acceleratorTable;
282 while (result = GetMessage(&message, NULL, 0, 0))
284 BOOLEAN processed =
FALSE;
292 for (i = 0; i < FilterList->
Count; i++)
317 for (i = 0; i < DialogList->
Count; i++)
319 if (IsDialogMessage((HWND)DialogList->
Items[i], &message))
330 TranslateMessage(&message);
331 DispatchMessage(&message);
337 return (
LONG)message.wParam;
341 _In_ HWND DialogWindowHandle
351 _In_ HWND DialogWindowHandle
359 indexOfDialog = PhFindItemList(DialogList, (PVOID)DialogWindowHandle);
361 if (indexOfDialog != -1)
392 indexOfFilter = PhFindItemList(FilterList, FilterEntry);
394 if (indexOfFilter != -1)
416 SetForegroundWindow(hwnd);
426 INITCOMMONCONTROLSEX icex;
428 icex.dwSize =
sizeof(INITCOMMONCONTROLSEX);
431 ICC_LISTVIEW_CLASSES |
436 InitCommonControlsEx(&icex);
454 -MulDiv(Size, GetDeviceCaps(hdc, LOGPIXELSY), 72),
469 ReleaseDC(hWnd, hdc);
483 NONCLIENTMETRICS metrics = {
sizeof(metrics) };
486 success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0);
571 if (!PhSettingsFileName)
577 PhSettingsFileName = settingsFileName;
586 if (!PhSettingsFileName)
588 PhSettingsFileName =
PhGetKnownLocation(CSIDL_APPDATA, L
"\\Process Hacker 2\\settings.xml");
591 if (PhSettingsFileName)
598 if (status == STATUS_FILE_CORRUPT_ERROR)
602 MB_ICONWARNING | MB_YESNO,
603 L
"Process Hacker's settings file is corrupt. Do you want to reset it?\n"
604 L
"If you select No, the settings system will not function properly."
609 CHAR data[] =
"<settings></settings>";
615 PhSettingsFileName->
Buffer,
618 FILE_SHARE_READ | FILE_SHARE_DELETE,
623 NtWriteFile(fileHandle, NULL, NULL, NULL, &isb, data,
sizeof(data) - 1, NULL, NULL);
632 PhSettingsFileName = NULL;
645 sampleCount = (GetSystemMetrics(SM_CXVIRTUALSCREEN) + 1) / 2;
647 if (sampleCount > 2048)
654 #define PH_ARG_SETTINGS 1
655 #define PH_ARG_NOSETTINGS 2
656 #define PH_ARG_SHOWVISIBLE 3
657 #define PH_ARG_SHOWHIDDEN 4
658 #define PH_ARG_COMMANDMODE 5
659 #define PH_ARG_COMMANDTYPE 6
660 #define PH_ARG_COMMANDOBJECT 7
661 #define PH_ARG_COMMANDACTION 8
662 #define PH_ARG_COMMANDVALUE 9
663 #define PH_ARG_RUNASSERVICEMODE 10
664 #define PH_ARG_NOKPH 11
665 #define PH_ARG_INSTALLKPH 12
666 #define PH_ARG_UNINSTALLKPH 13
667 #define PH_ARG_DEBUG 14
668 #define PH_ARG_HWND 15
669 #define PH_ARG_POINT 16
670 #define PH_ARG_SHOWOPTIONS 17
671 #define PH_ARG_PHSVC 18
672 #define PH_ARG_NOPLUGINS 19
673 #define PH_ARG_NEWINSTANCE 20
674 #define PH_ARG_ELEVATE 21
675 #define PH_ARG_SILENT 22
676 #define PH_ARG_HELP 23
677 #define PH_ARG_SELECTPID 24
678 #define PH_ARG_PRIORITY 25
679 #define PH_ARG_PLUGIN 26
680 #define PH_ARG_SELECTTAB 27
738 PhStartupParameters.
WindowHandle = (HWND)(ULONG_PTR)integer;
781 PhStartupParameters.
SelectPid = (ULONG)integer;
871 ) || PhStartupParameters.
Help)
875 L
"Command line options:\n\n"
877 L
"-ctype command-type\n"
878 L
"-cobject command-object\n"
879 L
"-caction command-action\n"
880 L
"-cvalue command-value\n"
890 L
"-plugin pluginname:value\n"
891 L
"-priority r|h|n|l\n"
893 L
"-selectpid pid-to-select\n"
894 L
"-selecttab name-of-tab-to-select\n"
895 L
"-settings filename\n"
900 if (PhStartupParameters.
Help)
915 status =
KphInstallEx(L
"KProcessHacker2", kprocesshackerFileName->
Buffer, ¶meters);
918 PhShowStatus(NULL, L
"Unable to install KProcessHacker", status, 0);
930 PhShowStatus(NULL, L
"Unable to uninstall KProcessHacker", status, 0);
949 if (PhStartupParameters.
Debug)
964 TOKEN_ADJUST_PRIVILEGES,
968 CHAR privilegesBuffer[FIELD_OFFSET(TOKEN_PRIVILEGES, Privileges) +
sizeof(LUID_AND_ATTRIBUTES) * 8];
969 PTOKEN_PRIVILEGES privileges;
972 privileges = (PTOKEN_PRIVILEGES)privilegesBuffer;
973 privileges->PrivilegeCount = 8;
975 for (i = 0; i < privileges->PrivilegeCount; i++)
977 privileges->Privileges[i].Attributes = SE_PRIVILEGE_ENABLED;
978 privileges->Privileges[i].Luid.HighPart = 0;
999 NtClose(tokenHandle);