116116#define IDM_QOS_SAVE 106
117117#define IDC_CHECK_ALL 107
118118#define IDC_UNCHECK 108
119+ #define IDM_CRITICAL 109
120+ #define IDM_KILL 110
119121HINSTANCE hInst ;
120122HWND hwndDlg ;
121123HWND hwndToolTip ;
@@ -172,6 +174,7 @@ void _drain()
172174 HANDLE hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_SET_QUOTA , false, GetCurrentProcessId ());
173175 //drenar WorkingSet
174176 SetProcessWorkingSetSize (hProcess , (SIZE_T ) - 1 , (SIZE_T ) - 1 );
177+ CloseHandle (hProcess );
175178}
176179
177180//Leer REG_SZ del registro
@@ -627,6 +630,29 @@ void SetIdealProcessor(DWORD dwProcessId, DWORD dwIdealProcessor)
627630 }
628631}
629632
633+ BOOL IsBoost (DWORD dwProcessId ){
634+ HANDLE hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION , FALSE, dwProcessId );
635+ BOOL pDisablePriorityBoost ;
636+ GetProcessPriorityBoost (hProcess , & pDisablePriorityBoost );
637+ CloseHandle (hProcess );
638+
639+ if (pDisablePriorityBoost ) {
640+ return FALSE;
641+ } else {
642+ return TRUE;
643+ }
644+ }
645+
646+ void SetProcessBoost (DWORD dwProcessId , BOOL pBoost ){
647+ HANDLE hProcess = OpenProcess (PROCESS_SET_INFORMATION , FALSE, dwProcessId );
648+ if (pBoost ){
649+ SetProcessPriorityBoost (hProcess , FALSE);
650+ } else {
651+ SetProcessPriorityBoost (hProcess , TRUE);
652+ }
653+ CloseHandle (hProcess );
654+ }
655+
630656void SetProcessPriority (DWORD dwProcessId , DWORD dwPriorityClass )
631657{
632658
@@ -671,6 +697,7 @@ void SetProcessPriority(DWORD dwProcessId, DWORD dwPriorityClass)
671697
672698 // Establecer prioridad
673699 SetPriorityClass (hProcess , dwPriorityClass );
700+ CloseHandle (hProcess );
674701
675702}
676703
@@ -682,6 +709,7 @@ DWORD GetProcessPriority(DWORD dwProcessId)
682709 }
683710 DWORD dwPriorityClass ;
684711 DWORD dwActualPriorityClass = GetPriorityClass (hProcess );
712+ CloseHandle (hProcess );
685713
686714 switch (dwActualPriorityClass )
687715 {
@@ -742,6 +770,7 @@ void SetPriority(const char* PriorityType, DWORD dwProcessId, ULONG Priority){
742770 IoPrio .IoPriority = Priority ;
743771 NtSetInformationProcess (hProcess , ProcessIoPriority , & IoPrio , sizeof (IoPrio ));
744772 }
773+ CloseHandle (hProcess );
745774}
746775
747776bool GetPriority (const char * PriorityType , DWORD dwProcessId , ULONG & Priority ) {
@@ -799,6 +828,7 @@ void SetProcessQos(const char* QosType, DWORD dwProcessId)
799828 PowerThrottling .StateMask = 0x0 ;
800829 SetProcessInformation (hProcess , ProcessPowerThrottling , & PowerThrottling , sizeof (PowerThrottling ));
801830 }
831+ CloseHandle (hProcess );
802832}
803833
804834void GetProcessQos (DWORD dwProcessId , ULONG & Qos ) {
@@ -884,6 +914,30 @@ void _SR(const char* ActionType, DWORD dwProcessId) {
884914 }
885915}
886916
917+ BOOL IsCritical (DWORD dwProcessId ){
918+ HANDLE hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION , FALSE, dwProcessId );
919+ BOOL Critical ;
920+ IsProcessCritical (hProcess , & Critical );
921+ CloseHandle (hProcess );
922+ if (Critical ){
923+ return TRUE;
924+ } else {
925+ return FALSE;
926+ }
927+ }
928+
929+ void SetProcessCritical (DWORD dwProcessId , BOOL Critical ){
930+ HANDLE hProcess = OpenProcess (PROCESS_SET_INFORMATION , FALSE, dwProcessId );
931+ ULONG bBreakOnTermination ;
932+ if (Critical ){
933+ bBreakOnTermination = 1 ;
934+ } else {
935+ bBreakOnTermination = 0 ;
936+ }
937+ NtSetInformationProcess (hProcess , ProcessBreakOnTermination , & bBreakOnTermination , sizeof (bBreakOnTermination ));
938+ CloseHandle (hProcess );
939+ }
940+
887941DWORD GetProcInfo (DWORD dwProcessId , LPSTR lpPath , DWORD nSize )
888942{
889943 HANDLE hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION , FALSE, dwProcessId );
@@ -1038,12 +1092,8 @@ void CheckMenuItemProcess(HMENU hMenu, char* ProcessName, DWORD dwProcessId){
10381092 }
10391093
10401094 // Verificar PriorityBoost
1041- HANDLE hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION , FALSE, dwProcessId );
1042- BOOL pDisablePriorityBoost ;
1043- if (GetProcessPriorityBoost (hProcess , & pDisablePriorityBoost )) {
1044- if (pDisablePriorityBoost == FALSE) {
1045- CheckMenuItem (hMenu , IDM_CPU_PRIORITY_BOOST , MF_BYCOMMAND | MF_CHECKED );
1046- }
1095+ if (IsBoost (dwProcessId )) {
1096+ CheckMenuItem (hMenu , IDM_CPU_PRIORITY_BOOST , MF_BYCOMMAND | MF_CHECKED );
10471097 }
10481098
10491099 if (RegKeyQuery (HKEY_CURRENT_USER , registryKey , "PriorityBoost" ) != nullptr ) {
@@ -1072,6 +1122,9 @@ void CheckMenuItemProcess(HMENU hMenu, char* ProcessName, DWORD dwProcessId){
10721122 ModifyMenu (hMenu , IDM_SUSPEND_RESUME , MF_BYCOMMAND | MF_STRING , IDM_SUSPEND_RESUME , "Suspend" );
10731123 }
10741124
1125+ if (IsCritical (dwProcessId )){
1126+ CheckMenuItem (hMenu , IDM_CRITICAL , MF_BYCOMMAND | MF_CHECKED );
1127+ }
10751128}
10761129
10771130void LoadConfigProcess (const char * ProcessName , DWORD dwProcessId )
@@ -1146,11 +1199,10 @@ void LoadConfigProcess(const char* ProcessName, DWORD dwProcessId)
11461199 // Cargar PriorityBoost
11471200 char * priorityBoost = RegKeyQuery (HKEY_CURRENT_USER , registryKey , "PriorityBoost" );
11481201 if (priorityBoost != nullptr ) {
1149- HANDLE hProcess = OpenProcess (PROCESS_SET_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION , FALSE, dwProcessId );
11501202 if (strcmp (priorityBoost , "0" ) == 0 ) {
1151- SetProcessPriorityBoost ( hProcess , TRUE);
1203+ SetProcessBoost ( dwProcessId , TRUE);
11521204 } else {
1153- SetProcessPriorityBoost ( hProcess , FALSE);
1205+ SetProcessBoost ( dwProcessId , FALSE);
11541206 }
11551207 }
11561208
0 commit comments