24 #include <phappresource.h>
29 #define INTENT_PROCESS_COMMENT 0x1
30 #define INTENT_PROCESS_PRIORITY_CLASS 0x2
31 #define INTENT_PROCESS_IO_PRIORITY 0x4
33 #define PROCESS_PRIORITY_SAVE_ID 1
34 #define PROCESS_PRIORITY_SAVE_FOR_THIS_COMMAND_LINE_ID 2
35 #define PROCESS_IO_PRIORITY_SAVE_ID 3
36 #define PROCESS_IO_PRIORITY_SAVE_FOR_THIS_COMMAND_LINE_ID 4
38 #define COMMENT_COLUMN_ID 1
40 typedef struct _PROCESS_EXTENSION
48 typedef struct _PROCESS_COMMENT_PAGE_CONTEXT
53 typedef struct _SERVICE_EXTENSION
60 typedef struct _SERVICE_COMMENT_PAGE_CONTEXT
145 if (Object->Comment->Length == 0 && Object->PriorityClass == 0 && Object->IoPriorityPlusOne == 0)
155 HANDLE processHandle;
156 ULONG ioPriority = -1;
172 NtClose(processHandle);
184 case PHAPP_ID_PRIORITY_REALTIME:
186 case PHAPP_ID_PRIORITY_HIGH:
188 case PHAPP_ID_PRIORITY_ABOVENORMAL:
190 case PHAPP_ID_PRIORITY_NORMAL:
192 case PHAPP_ID_PRIORITY_BELOWNORMAL:
194 case PHAPP_ID_PRIORITY_IDLE:
221 _In_opt_ PVOID Parameter,
222 _In_opt_ PVOID Context
251 _In_opt_ PVOID Parameter,
252 _In_opt_ PVOID Context
259 _In_opt_ PVOID Parameter,
260 _In_opt_ PVOID Context
272 _In_opt_ PVOID Parameter,
273 _In_opt_ PVOID Context
283 switch (menuItem->
Id)
291 object->PriorityClass = 0;
312 object->PriorityClass = 0;
332 object->IoPriorityPlusOne = 0;
353 object->IoPriorityPlusOne = 0;
371 _In_opt_ PVOID Parameter,
372 _In_opt_ PVOID Context
380 case PHAPP_ID_PRIORITY_REALTIME:
381 case PHAPP_ID_PRIORITY_HIGH:
382 case PHAPP_ID_PRIORITY_ABOVENORMAL:
383 case PHAPP_ID_PRIORITY_NORMAL:
384 case PHAPP_ID_PRIORITY_BELOWNORMAL:
385 case PHAPP_ID_PRIORITY_IDLE:
387 BOOLEAN changed =
FALSE;
389 ULONG numberOfProcesses;
395 for (i = 0; i < numberOfProcesses; i++)
405 object->PriorityClass = newPriorityClass;
423 BOOLEAN changed =
FALSE;
425 ULONG numberOfProcesses;
431 for (i = 0; i < numberOfProcesses; i++)
441 object->IoPriorityPlusOne = newIoPriorityPlusOne;
461 PLIST_ENTRY listEntry;
473 extension->Valid =
FALSE;
475 listEntry = listEntry->Flink;
486 if (!Extension->Valid)
503 Extension->Valid =
TRUE;
511 PLIST_ENTRY listEntry;
523 extension->Valid =
FALSE;
525 listEntry = listEntry->Flink;
536 if (!Extension->Valid)
553 Extension->Valid =
TRUE;
558 _In_opt_ PVOID Parameter,
559 _In_opt_ PVOID Context
576 switch (message->
SubId)
595 switch (message->
SubId)
614 _In_opt_ PVOID Parameter,
615 _In_opt_ PVOID Context
622 _In_opt_ PVOID Parameter,
623 _In_opt_ PVOID Context
637 _In_ BOOLEAN UseSelectionForHook
647 if (priorityMenuItem =
PhFindEMenuItem(MenuInfo->Menu, 0, L
"Priority", 0))
653 if (!ProcessItem->CommandLine)
667 if (ioPriorityMenuItem =
PhFindEMenuItem(MenuInfo->Menu, 0, L
"I/O Priority", 0))
673 if (!ProcessItem->CommandLine)
686 PhPluginAddMenuHook(MenuInfo, PluginInstance, UseSelectionForHook ? NULL : ProcessItem->ProcessId);
690 _In_opt_ PVOID Parameter,
691 _In_opt_ PVOID Context
696 if (menuInfo->
u.
Process.NumberOfProcesses != 1)
721 _In_opt_ PVOID Parameter,
722 _In_opt_ PVOID Context
731 column.
Text = L
"Comment";
739 _In_opt_ PVOID Parameter,
740 _In_opt_ PVOID Context
744 PROPSHEETPAGE propSheetPage;
748 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
749 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
750 propSheetPage.dwFlags = PSP_USETITLE;
751 propSheetPage.hInstance = PluginInstance->
DllBase;
753 propSheetPage.pszTitle = L
"Comment";
755 propSheetPage.lParam = (LPARAM)objectProperties->
Parameter;
756 objectProperties->
Pages[objectProperties->
NumberOfPages++] = CreatePropertySheetPage(&propSheetPage);
779 _In_opt_ PVOID Parameter,
780 _In_opt_ PVOID Context
789 column.
Text = L
"Comment";
797 _In_opt_ PVOID Parameter,
798 _In_opt_ PVOID Context
807 _In_opt_ PVOID Parameter,
808 _In_opt_ PVOID Context
814 extension->Valid =
FALSE;
818 _In_opt_ PVOID Parameter,
819 _In_opt_ PVOID Context
822 PLIST_ENTRY listEntry;
839 processItem = extension->ProcessItem;
845 HANDLE processHandle;
856 NtSetInformationProcess(processHandle, ProcessPriorityClass, &priorityClass,
sizeof(
PROCESS_PRIORITY_CLASS));
858 NtClose(processHandle);
867 HANDLE processHandle;
876 NtClose(processHandle);
881 listEntry = listEntry->Flink;
898 extension->ProcessItem = processItem;
951 _In_ HINSTANCE Instance,
953 _Reserved_ PVOID Reserved
956 if (Reason == DLL_PROCESS_ATTACH)
960 PluginInstance =
PhRegisterPlugin(L
"ProcessHacker.UserNotes", Instance, &info);
967 info->
Description = L
"Allows the user to add comments for processes and services. Also allows the user to save process priority.";
968 info->
Url = L
"http://processhacker.sf.net/forums/viewtopic.php?t=1120";
1012 {
StringSettingType, L
"ProcessHacker.UserNotes.DatabasePath", L
"%APPDATA%\\Process Hacker 2\\usernotesdb.xml" }
1042 switch (LOWORD(wParam))
1045 EndDialog(hwndDlg, IDCANCEL);
1052 EndDialog(hwndDlg, IDOK);
1059 { L
"XML files (*.xml)", L
"*.xml" },
1060 { L
"All files (*.*)", L
"*.*" }
1097 LPPROPSHEETPAGE propSheetPage;
1104 context = propPageContext->
Context;
1119 propPageContext->
Context = context;
1123 SendMessage(GetDlgItem(hwndDlg,
IDC_COMMENT), EM_SETLIMITTEXT, UNICODE_STRING_MAX_CHARS, 0);
1144 context->OriginalComment = comment;
1154 BOOLEAN matchCommandLine;
1155 BOOLEAN done =
FALSE;
1161 matchCommandLine =
FALSE;
1165 if (processItem->
CommandLine && !matchCommandLine)
1177 L
"Do you want to replace the comment for %s which is currently\n \"%s\"\n"
1196 if (MessageBox(hwndDlg, message->
Buffer, L
"Comment", MB_ICONQUESTION | MB_YESNO) == IDNO)
1208 if (comment->
Length != 0)
1210 if (matchCommandLine)
1256 switch (LOWORD(wParam))
1260 if (HIWORD(wParam) == EN_CHANGE)
1266 SetDlgItemText(hwndDlg,
IDC_COMMENT, context->OriginalComment->Buffer);
1267 SendMessage(GetDlgItem(hwndDlg,
IDC_COMMENT), EM_SETSEL, 0, -1);
1289 if (uMsg == WM_INITDIALOG)
1294 SetProp(hwndDlg, L
"Context", (HANDLE)context);
1300 if (uMsg == WM_DESTROY)
1301 RemoveProp(hwndDlg, L
"Context");
1311 LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
1316 context->ServiceItem = serviceItem;
1323 SendMessage(GetDlgItem(hwndDlg,
IDC_COMMENT), EM_SETLIMITTEXT, UNICODE_STRING_MAX_CHARS, 0);
1334 SetDlgItemText(hwndDlg,
IDC_COMMENT, comment->Buffer);
1351 switch (LOWORD(wParam))
1355 if (HIWORD(wParam) == EN_CHANGE)
1364 LPNMHDR header = (LPNMHDR)lParam;
1366 switch (header->code)
1368 case PSN_KILLACTIVE:
1370 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
FALSE);
1382 if (comment->
Length != 0)
1399 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);