Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LuSlower authored Jul 15, 2024
1 parent 8a2bc44 commit 8fd4ec2
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 27 deletions.
57 changes: 39 additions & 18 deletions SetProcessGui/SetProcessGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
char* start = RegKeyQuery(HKEY_CURRENT_USER, "Software\\SetProcess", "Start");
if (start)
{
Sleep(5000);
CheckDlgButton(hwndDlg, _START, BST_CHECKED);
}

Expand Down Expand Up @@ -341,19 +340,15 @@ BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (index != LB_ERR)
{
HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
BOOL pDisablePriorityBoost;
if (GetProcessPriorityBoost(hProcess, &pDisablePriorityBoost)) {
if (pDisablePriorityBoost == FALSE) {
SetProcessPriorityBoost(hProcess, TRUE);
if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) {
RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "0");
}
} else {
SetProcessPriorityBoost(hProcess, FALSE);
if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) {
RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "1");
}
if (IsBoost(dwProcessId)) {
SetProcessBoost(dwProcessId, FALSE);
if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) {
RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "0");
}
} else {
SetProcessBoost(dwProcessId, TRUE);
if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) {
RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "1");
}
}
}
Expand Down Expand Up @@ -679,9 +674,29 @@ BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
return TRUE;

case IDM_EXIT:
case IDM_CRITICAL:
{
PostMessage(hwndDlg, WM_CLOSE, 0, 0);
if (IsCritical(dwProcessId)){
SetProcessCritical(dwProcessId, FALSE);
} else {
SetProcessCritical(dwProcessId, TRUE);
}
}
return TRUE;

case IDM_KILL:
{
if (IsCritical(dwProcessId)){
MessageBox(0, "Stopping a critical process will result in a BSOD with code CRITICAL_PROCESS_DIED", "Error", MB_OK | MB_ICONERROR);
break;
}

HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
if(MessageBox(0, "Do you really want to kill the process?", "Warning", MB_OKCANCEL | MB_ICONWARNING) == 1){
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
PopulateListBox(hListBox);
}
}
return TRUE;

Expand All @@ -691,10 +706,16 @@ BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
return TRUE;

} //end Switch wParam
case IDM_EXIT:
{
PostMessage(hwndDlg, WM_CLOSE, 0, 0);
}
return TRUE;

}
return TRUE;
}
return TRUE; //end WM_COMMAND
return TRUE;

case WM_CLOSE:
{
Expand Down
70 changes: 61 additions & 9 deletions SetProcessGui/SetProcessGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
#define IDM_QOS_SAVE 106
#define IDC_CHECK_ALL 107
#define IDC_UNCHECK 108
#define IDM_CRITICAL 109
#define IDM_KILL 110
HINSTANCE hInst;
HWND hwndDlg;
HWND hwndToolTip;
Expand Down Expand Up @@ -172,6 +174,7 @@ void _drain()
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_SET_QUOTA, false, GetCurrentProcessId());
//drenar WorkingSet
SetProcessWorkingSetSize(hProcess, (SIZE_T) -1, (SIZE_T) -1);
CloseHandle(hProcess);
}

//Leer REG_SZ del registro
Expand Down Expand Up @@ -627,6 +630,29 @@ void SetIdealProcessor(DWORD dwProcessId, DWORD dwIdealProcessor)
}
}

BOOL IsBoost(DWORD dwProcessId){
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
BOOL pDisablePriorityBoost;
GetProcessPriorityBoost(hProcess, &pDisablePriorityBoost);
CloseHandle(hProcess);

if (pDisablePriorityBoost) {
return FALSE;
} else {
return TRUE;
}
}

void SetProcessBoost(DWORD dwProcessId, BOOL pBoost){
HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
if (pBoost){
SetProcessPriorityBoost(hProcess, FALSE);
} else {
SetProcessPriorityBoost(hProcess, TRUE);
}
CloseHandle(hProcess);
}

void SetProcessPriority(DWORD dwProcessId, DWORD dwPriorityClass)
{

Expand Down Expand Up @@ -671,6 +697,7 @@ void SetProcessPriority(DWORD dwProcessId, DWORD dwPriorityClass)

// Establecer prioridad
SetPriorityClass(hProcess, dwPriorityClass);
CloseHandle(hProcess);

}

Expand All @@ -682,6 +709,7 @@ DWORD GetProcessPriority(DWORD dwProcessId)
}
DWORD dwPriorityClass;
DWORD dwActualPriorityClass = GetPriorityClass(hProcess);
CloseHandle(hProcess);

switch (dwActualPriorityClass)
{
Expand Down Expand Up @@ -742,6 +770,7 @@ void SetPriority(const char* PriorityType, DWORD dwProcessId, ULONG Priority){
IoPrio.IoPriority = Priority;
NtSetInformationProcess(hProcess, ProcessIoPriority, &IoPrio, sizeof(IoPrio));
}
CloseHandle(hProcess);
}

bool GetPriority(const char* PriorityType, DWORD dwProcessId, ULONG& Priority) {
Expand Down Expand Up @@ -799,6 +828,7 @@ void SetProcessQos(const char* QosType, DWORD dwProcessId)
PowerThrottling.StateMask = 0x0;
SetProcessInformation(hProcess, ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling));
}
CloseHandle(hProcess);
}

void GetProcessQos(DWORD dwProcessId, ULONG& Qos) {
Expand Down Expand Up @@ -884,6 +914,30 @@ void _SR(const char* ActionType, DWORD dwProcessId) {
}
}

BOOL IsCritical(DWORD dwProcessId){
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
BOOL Critical;
IsProcessCritical(hProcess, &Critical);
CloseHandle(hProcess);
if (Critical){
return TRUE;
} else {
return FALSE;
}
}

void SetProcessCritical(DWORD dwProcessId, BOOL Critical){
HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
ULONG bBreakOnTermination;
if (Critical){
bBreakOnTermination = 1;
} else {
bBreakOnTermination = 0;
}
NtSetInformationProcess(hProcess, ProcessBreakOnTermination, &bBreakOnTermination, sizeof(bBreakOnTermination));
CloseHandle(hProcess);
}

DWORD GetProcInfo(DWORD dwProcessId, LPSTR lpPath, DWORD nSize)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
Expand Down Expand Up @@ -1038,12 +1092,8 @@ void CheckMenuItemProcess(HMENU hMenu, char* ProcessName, DWORD dwProcessId){
}

// Verificar PriorityBoost
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
BOOL pDisablePriorityBoost;
if (GetProcessPriorityBoost(hProcess, &pDisablePriorityBoost)) {
if (pDisablePriorityBoost == FALSE) {
CheckMenuItem(hMenu, IDM_CPU_PRIORITY_BOOST, MF_BYCOMMAND | MF_CHECKED);
}
if (IsBoost(dwProcessId)) {
CheckMenuItem(hMenu, IDM_CPU_PRIORITY_BOOST, MF_BYCOMMAND | MF_CHECKED);
}

if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) {
Expand Down Expand Up @@ -1072,6 +1122,9 @@ void CheckMenuItemProcess(HMENU hMenu, char* ProcessName, DWORD dwProcessId){
ModifyMenu(hMenu, IDM_SUSPEND_RESUME, MF_BYCOMMAND | MF_STRING, IDM_SUSPEND_RESUME, "Suspend");
}

if (IsCritical(dwProcessId)){
CheckMenuItem(hMenu, IDM_CRITICAL, MF_BYCOMMAND | MF_CHECKED);
}
}

void LoadConfigProcess(const char* ProcessName, DWORD dwProcessId)
Expand Down Expand Up @@ -1146,11 +1199,10 @@ void LoadConfigProcess(const char* ProcessName, DWORD dwProcessId)
// Cargar PriorityBoost
char* priorityBoost = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost");
if (priorityBoost != nullptr) {
HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
if (strcmp(priorityBoost, "0") == 0) {
SetProcessPriorityBoost(hProcess, TRUE);
SetProcessBoost(dwProcessId, TRUE);
} else {
SetProcessPriorityBoost(hProcess, FALSE);
SetProcessBoost(dwProcessId, FALSE);
}
}

Expand Down

0 comments on commit 8fd4ec2

Please sign in to comment.