From b9636181c70b03a3b54ff4cef60741035c1eb3ab Mon Sep 17 00:00:00 2001 From: "Dr.LuSlower" <148411728+LuSlower@users.noreply.github.com> Date: Fri, 12 Jul 2024 03:57:45 -0500 Subject: [PATCH] Add files via upload --- SetProcessGui/SetProcessGui.cbp | 34 + SetProcessGui/SetProcessGui.cpp | 769 ++++++++++ SetProcessGui/SetProcessGui.cscope_file_list | 4 + SetProcessGui/SetProcessGui.h | 1330 ++++++++++++++++++ SetProcessGui/SetProcessGui.ico | Bin 0 -> 4286 bytes SetProcessGui/SetProcessGui.layout | 20 + SetProcessGui/SetProcessGui.rc | 185 +++ SetProcessGui/manifest.xml | 17 + 8 files changed, 2359 insertions(+) create mode 100644 SetProcessGui/SetProcessGui.cbp create mode 100644 SetProcessGui/SetProcessGui.cpp create mode 100644 SetProcessGui/SetProcessGui.cscope_file_list create mode 100644 SetProcessGui/SetProcessGui.h create mode 100644 SetProcessGui/SetProcessGui.ico create mode 100644 SetProcessGui/SetProcessGui.layout create mode 100644 SetProcessGui/SetProcessGui.rc create mode 100644 SetProcessGui/manifest.xml diff --git a/SetProcessGui/SetProcessGui.cbp b/SetProcessGui/SetProcessGui.cbp new file mode 100644 index 0000000..ab4b365 --- /dev/null +++ b/SetProcessGui/SetProcessGui.cbp @@ -0,0 +1,34 @@ + + + + + + diff --git a/SetProcessGui/SetProcessGui.cpp b/SetProcessGui/SetProcessGui.cpp new file mode 100644 index 0000000..63065b7 --- /dev/null +++ b/SetProcessGui/SetProcessGui.cpp @@ -0,0 +1,769 @@ +#include "SetProcessGui.h" + +BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG: + { + // Impersonacion + ImpersonateSystem(); + EnablePrivilege(GetCurrentProcessId(), SE_INC_BASE_PRIORITY_NAME); + EnablePrivilege(GetCurrentProcessId(), SE_DEBUG_NAME); + + //establecer hIcon + HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); + + // Inicializar la estructura NOTIFYICONDATA + nid.cbSize = sizeof(NOTIFYICONDATA); + nid.hWnd = hwndDlg; + nid.uID = 1; + nid.uFlags = NIF_ICON | NIF_MESSAGE; + nid.uCallbackMessage = WM_ICON; + nid.hIcon = hIcon; + strcpy(nid.szTip, "SetProcess"); + + // Destruir icono + DestroyIcon(hIcon); + + // Agregar el icono a la bandeja del sistema + Shell_NotifyIcon(NIM_ADD, &nid); + + // Crear ListBox + PopulateListBox(GetDlgItem(hwndDlg, IDC_LISTP)); + + // Crear ToolTip + CreateToolTip(hwndDlg, GetDlgItem(hwndDlg, IDC_LISTP), NULL); + + // verificar si el inicio automatico esta habilitado + char* start = RegKeyQuery(HKEY_CURRENT_USER, "Software\\SetProcess", "Start"); + if (start) + { + Sleep(5000); + CheckDlgButton(hwndDlg, _START, BST_CHECKED); + } + + if (start) + { + //enviar mensaje de ocultar el dialogo + PostMessage(hwndDlg, WM_HIDE, 0, 0); + } + + _drain(); + + } + return TRUE; + + case WM_HIDE: + { + // Ocultar dialogo + ShowWindow(hwndDlg, SW_HIDE); + } + return TRUE; + + case WM_ICON: + { + switch (lParam) + { + case WM_RBUTTONDOWN: + { + // Mostrar el menú de la bandeja al hacer clic derecho en el icono + ShowTrayMenu(hwndDlg); + } + return TRUE; + case WM_LBUTTONDOWN: + { + //Mostrar dialogo al hacer clic izquierdo + SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_END); + ShowWindow(hwndDlg, SW_SHOWDEFAULT); + PopulateListBox(GetDlgItem(hwndDlg, IDC_LISTP)); + + } + return TRUE; + } + } + return TRUE; + + case WM_CONTEXTMENU: + { + HWND hListBox = GetDlgItem(hwndDlg, IDC_LISTP); + if ((HWND)wParam == hListBox) // Verifica si el evento ocurrió en el ListBox + { + int index = SendMessage(hListBox, LB_GETCURSEL, 0, 0); + if (index != LB_ERR) + { + // Obtener el texto del item seleccionado, Obtener PID + char itemText[MAX_PATH]; + SendMessage(hListBox, LB_GETTEXT, index, (LPARAM)itemText); + DWORD dwProcessId = ExtractPID(itemText); + char ProcessName[MAX_PATH]; + ExtractProcessName(itemText, ProcessName, sizeof(ProcessName)); + + // Obtén las coordenadas del cursor en la pantalla + int x = GET_X_LPARAM(lParam); + int y = GET_Y_LPARAM(lParam); + + // Mostrar el menú contextual del ListBox + ShowListBoxMenu(hListBox, ProcessName, dwProcessId, x, y); + } + } + } + return TRUE; + + case WM_COMMAND: + { + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + DWORD MAX_CPUS = sysinfo.dwNumberOfProcessors; + + // Obtener el item seleccionado + HWND hListBox = GetDlgItem(hwndDlg, IDC_LISTP); + int index = SendMessage(hListBox, LB_GETCURSEL, 0, 0); + + // Obtener el texto del item seleccionado, Obtener PID + char itemText[MAX_PATH]; + SendMessage(hListBox, LB_GETTEXT, index, (LPARAM)itemText); + DWORD dwProcessId = ExtractPID(itemText); + char ProcessName[MAX_PATH]; + ExtractProcessName(itemText, ProcessName, sizeof(ProcessName)); + + // Obtener privilegios + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + EnablePrivilege(dwProcessId, SE_INC_BASE_PRIORITY_NAME); + + // Construir la clave del registro + char registryKey[MAX_PATH]; + snprintf(registryKey, sizeof(registryKey), "Software\\SetProcess\\%s", ProcessName); + + switch(LOWORD(wParam)) + { + + case IDC_REFRESH: + { + // refrescar listbox + PopulateListBox(GetDlgItem(hwndDlg, IDC_LISTP)); + } + return TRUE; + case IDC_LISTP: + { + if (index != LB_ERR) + { + // Obtener el PID, Obtener Path y Refrescar ToolTip + char SzInfo[MAX_PATH] = { 0 }; + GetProcInfo(dwProcessId, SzInfo, MAX_PATH); + UpdateToolTipText(hListBox, SzInfo); + } + } + return TRUE; + + case IDM_CPUSETS: + { + if (index != LB_ERR) + { + DWORD CPUs[MAX_CPUS] = { 0 }; + + DWORD cpuBitmask = 0; + GROUP_AFFINITY cpuSetMasks[MAX_CPUS]; + USHORT actualCpuSetMaskCount = 0; + + // Obtener las máscaras de conjuntos de CPU predeterminadas + BOOL success = GetProcessCpuSetMask(dwProcessId, cpuSetMasks, MAX_CPUS, &actualCpuSetMaskCount); + + if (success) + { + // Preparar la bitmask para mostrar en el diálogo o cualquier otro uso + cpuBitmask = 0; + for (USHORT i = 0; i < actualCpuSetMaskCount; ++i) + { + cpuBitmask |= cpuSetMasks[i].Mask; + } + + // Actualizar CPUs[] según la bitmask obtenida + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + CPUs[i] = (cpuBitmask & (1ULL << i)) ? 1 : 0; + } + } + + // Mostrar el diálogo de bitmask con CPUs obtenidos o por defecto + ShowBitMaskDialog(hwndDlg, CPUs); + + bool OneProcessorSelected = false; + // Verificar si al menos un procesador está seleccionado + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + if (CPUs[i] == 1) + { + OneProcessorSelected = true; + break; + } + } + + if (!OneProcessorSelected) + { + // Revertir + SetProcessCpuSetMask(dwProcessId, NULL); + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "CpuSets"); + break; + } + + DWORD newCpuBitmask = 0; + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + if (CPUs[i] == 1) + { + newCpuBitmask |= (1 << i); + } + } + + // Establecer los conjuntos de CPU + SetProcessCpuSetMask(dwProcessId, newCpuBitmask); + + // Convertir la nueva bitmask a una cadena de bits para almacenar en el registro + char cpuBitmaskString[MAX_CPUS + 1] = { 0 }; // Más 1 para el terminador nulo + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + cpuBitmaskString[i] = (newCpuBitmask & (1 << i)) ? '1' : '0'; + } + + // Escribir la nueva bitmask en el registro + RegKeySet(HKEY_CURRENT_USER, registryKey, "CpuSets", cpuBitmaskString); + } + } + return TRUE; + + case IDM_IDEAL_PROCESSOR: + { + if (index != LB_ERR) + { + DWORD CPUs[MAX_CPUS] = { 0 }; + + // Cargar IdealProcesor si existe + char* IdealProcStr = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IdealProc"); + if (IdealProcStr != nullptr) + { + DWORD IdealProc = atoi(IdealProcStr); + memset(CPUs, 0, sizeof(DWORD) * MAX_CPUS); + + // Establecer el bit correspondiente en CPUs + if (IdealProc < MAX_CPUS) { + CPUs[IdealProc] = 1; + } + } + + ShowBitMaskDialog(hwndDlg, CPUs); + int activeIndex = GetSingleCoreIndex(CPUs, MAX_CPUS); + if (activeIndex == -1){ + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "IdealProc"); + break; + } + + + // Establecer procesador ideal + SetIdealProcessor(dwProcessId, activeIndex); + + // Convertir el índice del procesador a cadena + char activeIndexStr[16]; + snprintf(activeIndexStr, sizeof(activeIndexStr), "%d", activeIndex); + RegKeySet(HKEY_CURRENT_USER, registryKey, "IdealProc", activeIndexStr); + + } + } + return TRUE; + + case IDM_AFFINITY: + { + if (index != LB_ERR) + { + DWORD CPUs[MAX_CPUS] = { 0 }; + DWORD_PTR dwProcessAffinityMask = GetProcessAffinity(dwProcessId); + if (dwProcessAffinityMask != 0) + { + // Preparar la bitmask para mostrar en el diálogo + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + if (dwProcessAffinityMask & (1 << i)) + { + CPUs[i] = 1; // Marcar el CPU i en el arreglo CPUs + } + else + { + CPUs[i] = 0; + } + } + } + + ShowBitMaskDialog(hwndDlg, CPUs); + + bool OneProcessorSelected = false; + bool AllProcessorsSelected = true; + DWORD selectedCoreCount = 0; + + // Verificar si al menos un procesador está seleccionado y contar los seleccionados + for (DWORD i = 0; i < MAX_CPUS; ++i) { + if (CPUs[i] == 1) { + OneProcessorSelected = true; + selectedCoreCount++; + } else { + AllProcessorsSelected = false; + } + } + + if (!OneProcessorSelected) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "AffinityMask"); + break; + } + + dwProcessAffinityMask = 0; + + // Configurar la máscara de afinidad de procesador + for (DWORD i = 0; i < MAX_CPUS; ++i) { + if (CPUs[i] != 0) { + dwProcessAffinityMask |= (1 << i); // Establecer el bit correspondiente a CPU i + } + } + + if (AllProcessorsSelected) { + // Establecer afinidad + SetProcessAffinity(dwProcessId, dwProcessAffinityMask); + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "AffinityMask"); + break; + } + + // Establecer afinidad + SetProcessAffinity(dwProcessId, dwProcessAffinityMask); + + // Convertir la nueva bitmask a una cadena de bits para almacenar en el registro + char AffinityMaskStr[MAX_CPUS + 1] = { 0 }; // Más 1 para el terminador nulo + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + AffinityMaskStr[i] = (dwProcessAffinityMask & (1 << i)) ? '1' : '0'; + } + + // Escribir la nueva bitmask en el registro + RegKeySet(HKEY_CURRENT_USER, registryKey, "AffinityMask", AffinityMaskStr); + + } + } + return TRUE; + + case IDM_CPU_PRIORITY_BOOST: + { + 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); + break; + } + } + SetProcessPriorityBoost(hProcess, FALSE); + } + + } + return TRUE; + + case IDM_CPU_PRIORITY_IDLE: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 0); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "0"); + } + } + + } + return TRUE; + + case IDM_CPU_PRIORITY_BELOW_NORMAL: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 1); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "1"); + } + + } + + } + return TRUE; + + case IDM_CPU_PRIORITY_NORMAL: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 2); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "2"); + } + } + } + return TRUE; + + case IDM_CPU_PRIORITY_ABOVE_NORMAL: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 3); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "3"); + } + } + } + return TRUE; + + case IDM_CPU_PRIORITY_HIGH: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 4); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "4"); + } + } + + } + return TRUE; + + case IDM_CPU_PRIORITY_REALTIME: + { + if (index != LB_ERR) + { + SetProcessPriority(dwProcessId, 5); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", "5"); + } + } + + } + return TRUE; + + case IDM_MEMORY_PRIORITY_VERYLOW: + { + if (index != LB_ERR) + { + SetPriority("MEM", dwProcessId, 1); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", "1"); + } + } + } + return TRUE; + + case IDM_MEMORY_PRIORITY_LOW: + { + if (index != LB_ERR) + { + SetPriority("MEM", dwProcessId, 2); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", "2"); + } + + } + } + return TRUE; + + case IDM_MEMORY_PRIORITY_MEDIUM: + { + if (index != LB_ERR) + { + SetPriority("MEM", dwProcessId, 3); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", "3"); + } + } + } + return TRUE; + + case IDM_MEMORY_PRIORITY_BELOWNORMAL: + { + if (index != LB_ERR) + { + SetPriority("MEM", dwProcessId, 4); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", "4"); + } + } + } + return TRUE; + + case IDM_MEMORY_PRIORITY_NORMAL: + { + if (index != LB_ERR) + { + SetPriority("MEM", dwProcessId, 5); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", "5"); + } + } + } + return TRUE; + + case IDM_IO_PRIORITY_VERYLOW: + { + if (index != LB_ERR) + { + SetPriority("IO", dwProcessId, 0); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "IoPriority", "0"); + } + } + } + return TRUE; + + case IDM_IO_PRIORITY_LOW: + { + if (index != LB_ERR) + { + SetPriority("IO", dwProcessId, 1); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "IoPriority", "1"); + } + } + } + return TRUE; + + case IDM_IO_PRIORITY_NORMAL: + { + if (index != LB_ERR) + { + SetPriority("IO", dwProcessId, 2); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "IoPriority", "2"); + } + } + } + return TRUE; + + case IDM_IO_PRIORITY_HIGH: + { + if (index != LB_ERR) + { + + SetPriority("IO", dwProcessId, 3); + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "IoPriority", "3"); + } + } + } + return TRUE; + + case IDM_QOS_ECOQOS: + { + if (index != LB_ERR) + { + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + + SetProcessQos("ECO", dwProcessId); + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "HighQos") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "HighQos"); + RegKeySet(HKEY_CURRENT_USER, registryKey, "EcoQos", "1"); + } + } + } + return TRUE; + + case IDM_QOS_HIGHQOS: + { + if (index != LB_ERR) + { + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + + SetProcessQos("HIGH", dwProcessId); + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "EcoQos") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "EcoQos"); + RegKeySet(HKEY_CURRENT_USER, registryKey, "HighQos", "1"); + } + } + } + return TRUE; + + case IDM_SUSPEND_RESUME: + { + if (index != LB_ERR) + { + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + if(IsSuspended(dwProcessId)) { + _SR("RESUME", dwProcessId); + } else { + _SR("SUSPEND", dwProcessId); + } + } + } + return TRUE; + + case IDM_CPU_PRIORITY_BOOST_SAVE: + { + + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + BOOL pDisablePriorityBoost; + if (GetProcessPriorityBoost(hProcess, &pDisablePriorityBoost)) { + if (pDisablePriorityBoost == FALSE) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "1"); + } else { + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityBoost", "0"); + } + } + } + return TRUE; + + case IDM_QOS_SAVE: + { + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "EcoQos") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "EcoQos"); + break; + } else if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "HighQos") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "HighQos"); + break; + } + + ULONG Qos; + GetProcessQos(dwProcessId, Qos); + + if (Qos == 0) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "HighQos", "1"); + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "EcoQos"); + } else if (Qos == PROCESS_POWER_THROTTLING_EXECUTION_SPEED) { + RegKeySet(HKEY_CURRENT_USER, registryKey, "EcoQos", "1"); + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "HighQos"); + } + } + return TRUE; + + case IDM_CPU_PRIORITY_SAVE: + { + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "PriorityClass"); + break; + } + + DWORD Priority = GetProcessPriority(dwProcessId); + char strPriority[2]; + sprintf_s(strPriority, sizeof(strPriority), "%lu", Priority); + RegKeySet(HKEY_CURRENT_USER, registryKey, "PriorityClass", strPriority); + } + return TRUE; + + case IDM_MEMORY_PRIORITY_SAVE: + { + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "MemoryPriority"); + break; + } + + ULONG Priority; + GetPriority("MEM", dwProcessId, Priority); + char strPriority[2]; + sprintf_s(strPriority, sizeof(strPriority), "%lu", Priority); + RegKeySet(HKEY_CURRENT_USER, registryKey, "MemoryPriority", strPriority); + } + return TRUE; + + case IDM_IO_PRIORITY_SAVE: + { + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + RegKeyDelete(HKEY_CURRENT_USER, registryKey, "IoPriority"); + break; + } + ULONG Priority; + GetPriority("IO", dwProcessId, Priority); + char strPriority[2]; + sprintf_s(strPriority, sizeof(strPriority), "%lu", Priority); + RegKeySet(HKEY_CURRENT_USER, registryKey, "IoPriority", strPriority); + } + return TRUE; + + case IDM_EXIT: + { + PostMessage(hwndDlg, WM_CLOSE, 0, 0); + } + return TRUE; + + case IDM_RESET: + { + RegKeyDelete(HKEY_CURRENT_USER, registryKey); + } + return TRUE; + + } //end Switch wParam + return TRUE; + } + return TRUE; //end WM_COMMAND + + case WM_CLOSE: + { + //comprobar valores + UINT state = IsDlgButtonChecked(hwndDlg, _START); + if (state == BST_CHECKED) + { + char path[MAX_PATH]; + if (GetModuleFileName(NULL, path, MAX_PATH) != 0) + { + RegKeySet(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "SetProcess", path); + RegKeySet(HKEY_CURRENT_USER, "Software\\SetProcess", "Start", "1"); + } + } + else + { + RegKeyDelete(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "SetProcess"); + RegKeyDelete(HKEY_CURRENT_USER, "Software\\SetProcess", "Start"); + } + //exit + Shell_NotifyIcon(NIM_DELETE, &nid); + DestroyWindow(hwndDlg); + } + return TRUE; + } + return FALSE; //end Switch +} + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + hInst=hInstance; + InitCommonControls(); + + // Configurar el WinEventHook + g_hookID = SetWinEventHook( + EVENT_SYSTEM_FOREGROUND, + EVENT_OBJECT_CREATE, + NULL, + WinEventProc, + 0, + 0, + WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS | WINEVENT_SKIPOWNTHREAD + ); + + // Cargar el acelerador + HWND hwndR = CreateDialog(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain); + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + + if(msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) + { + SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN); + ShowWindow(hwndR, SW_HIDE); + _drain(); + } + if (!IsDialogMessage(hwndR, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + if (!IsWindow(hwndR)) { + UnhookWinEvent(g_hookID); + DestroyWindow(hwndR); + DestroyWindow(hwndDlg); + break; // Salir del bucle si el HWND ya no existe + } + } + return TRUE; +} diff --git a/SetProcessGui/SetProcessGui.cscope_file_list b/SetProcessGui/SetProcessGui.cscope_file_list new file mode 100644 index 0000000..85ecc92 --- /dev/null +++ b/SetProcessGui/SetProcessGui.cscope_file_list @@ -0,0 +1,4 @@ +"E:\Documentos\CODEBLOCKS\SetProcessGui\SetProcessGui.cpp" +"E:\Documentos\CODEBLOCKS\SetProcessGui\manifest.xml" +"E:\Documentos\CODEBLOCKS\SetProcessGui\SetProcessGui.h" +"E:\Documentos\CODEBLOCKS\SetProcessGui\SetProcessGui.rc" diff --git a/SetProcessGui/SetProcessGui.h b/SetProcessGui/SetProcessGui.h new file mode 100644 index 0000000..f9021b6 --- /dev/null +++ b/SetProcessGui/SetProcessGui.h @@ -0,0 +1,1330 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define IDC_STATIC (-1) +#define DLG_MAIN 1 +#define IDC_REFRESH 2 +#define IDC_LISTP 3 +#define _START 4 +#define IDI_ICON 5 +#define IDM_EXIT 6 +#define WM_HIDE 7 +#define WM_ICON 8 +#define WM_TRAYICON (WM_ICON) +#define IDR_CONTEXT_MENU 9 +#define IDM_CPUSETS 10 +#define IDM_IDEAL_PROCESSOR 11 +#define IDM_AFFINITY 12 +#define IDM_CPU_PRIORITY_IDLE 14 +#define IDM_CPU_PRIORITY_BELOW_NORMAL 15 +#define IDM_CPU_PRIORITY_NORMAL 16 +#define IDM_CPU_PRIORITY_ABOVE_NORMAL 17 +#define IDM_CPU_PRIORITY_HIGH 18 +#define IDM_CPU_PRIORITY_REALTIME 19 +#define IDM_CPU_PRIORITY_BOOST 20 +#define IDM_MEMORY_PRIORITY_VERYLOW 21 +#define IDM_MEMORY_PRIORITY_LOW 22 +#define IDM_MEMORY_PRIORITY_MEDIUM 23 +#define IDM_MEMORY_PRIORITY_BELOWNORMAL 24 +#define IDM_MEMORY_PRIORITY_NORMAL 25 +#define IDM_IO_PRIORITY_VERYLOW 26 +#define IDM_IO_PRIORITY_LOW 27 +#define IDM_IO_PRIORITY_NORMAL 28 +#define IDM_IO_PRIORITY_HIGH 29 +#define IDM_QOS_ECOQOS 31 +#define IDM_QOS_HIGHQOS 32 +#define IDM_SUSPEND_RESUME 33 +#define IDC_CPU_0 35 +#define IDC_CPU_1 36 +#define IDC_CPU_2 37 +#define IDC_CPU_3 38 +#define IDC_CPU_4 39 +#define IDC_CPU_5 40 +#define IDC_CPU_6 41 +#define IDC_CPU_7 42 +#define IDC_CPU_8 43 +#define IDC_CPU_9 44 +#define IDC_CPU_10 45 +#define IDC_CPU_11 46 +#define IDC_CPU_12 47 +#define IDC_CPU_13 48 +#define IDC_CPU_14 49 +#define IDC_CPU_15 50 +#define IDC_CPU_16 51 +#define IDC_CPU_17 52 +#define IDC_CPU_18 53 +#define IDC_CPU_19 54 +#define IDC_CPU_20 55 +#define IDC_CPU_21 56 +#define IDC_CPU_22 57 +#define IDC_CPU_23 58 +#define IDC_CPU_24 59 +#define IDC_CPU_25 60 +#define IDC_CPU_26 61 +#define IDC_CPU_27 62 +#define IDC_CPU_28 63 +#define IDC_CPU_29 64 +#define IDC_CPU_30 65 +#define IDC_CPU_31 66 +#define IDC_CPU_32 67 +#define IDC_CPU_33 68 +#define IDC_CPU_34 69 +#define IDC_CPU_35 70 +#define IDC_CPU_36 71 +#define IDC_CPU_37 72 +#define IDC_CPU_38 73 +#define IDC_CPU_39 74 +#define IDC_CPU_40 75 +#define IDC_CPU_41 76 +#define IDC_CPU_42 77 +#define IDC_CPU_43 78 +#define IDC_CPU_44 79 +#define IDC_CPU_45 80 +#define IDC_CPU_46 81 +#define IDC_CPU_47 82 +#define IDC_CPU_48 83 +#define IDC_CPU_49 84 +#define IDC_CPU_50 85 +#define IDC_CPU_51 86 +#define IDC_CPU_52 87 +#define IDC_CPU_53 88 +#define IDC_CPU_54 89 +#define IDC_CPU_55 90 +#define IDC_CPU_56 91 +#define IDC_CPU_57 92 +#define IDC_CPU_58 93 +#define IDC_CPU_59 94 +#define IDC_CPU_60 95 +#define IDC_CPU_61 96 +#define IDC_CPU_62 97 +#define IDC_CPU_63 98 +#define IDC_SAVE_BITMASK 99 +#define DLG_BITMASK 100 +#define IDM_RESET 101 +#define IDM_CPU_PRIORITY_SAVE 102 +#define IDM_MEMORY_PRIORITY_SAVE 103 +#define IDM_IO_PRIORITY_SAVE 104 +#define IDM_CPU_PRIORITY_BOOST_SAVE 105 +#define IDM_QOS_SAVE 106 +#define IDC_CHECK_ALL 107 +#define IDC_UNCHECK 108 +HINSTANCE hInst; +HWND hwndDlg; +HWND hwndToolTip; + +extern "C" { + + NTSYSAPI NTSTATUS NTAPI NtSuspendProcess( + HANDLE ProcessHandle + ); + + NTSYSAPI NTSTATUS NTAPI NtResumeProcess( + HANDLE ProcessHandle + ); + + typedef struct _IO_PRIORITY_INFORMATION { + ULONG IoPriority; + } IO_PRIORITY_INFORMATION, *PIO_PRIORITY_INFORMATION; + + WINBASEAPI WINBOOL WINAPI SetProcessDefaultCpuSetMasks( + HANDLE Process, + PGROUP_AFFINITY CpuSetMasks, + USHORT CpuSetMaskCount + ); + + WINBASEAPI WINBOOL WINAPI GetProcessDefaultCpuSetMasks( + HANDLE Process, + PGROUP_AFFINITY CpuSetMasks, + USHORT CpuSetMaskCount, + PUSHORT RequiredMaskCount + ); + + typedef enum _PROCINFOCLAS { + ProcPowerThrottlingState = 77 + } PROCINFOCLASS; + + NTSYSAPI NTSTATUS NTAPI ZwQueryInformationProcess( + HANDLE ProcessHandle, + PROCINFOCLASS ProcessInformationClass, + PVOID ProcessInformation, + ULONG ProcessInformationLength, + PULONG ReturnLength + ); + + NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation ( + SYSTEM_INFORMATION_CLASS SystemInformationClass, + PVOID SystemInformation, + ULONG SystemInformationLength, + ULONG *ReturnLength + ); +} + +void _drain() +{ + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_SET_QUOTA, false, GetCurrentProcessId()); + //drenar WorkingSet + SetProcessWorkingSetSize(hProcess, (SIZE_T) -1, (SIZE_T) -1); +} + +//Leer REG_SZ del registro +char* RegKeyQuery(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpValueName) +{ + static char result[MAX_PATH]; // Static para que persista fuera del ámbito de la función + HKEY hSubKey; + if (RegOpenKeyExA(hKey, lpSubKey, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) + { + DWORD dwType; + DWORD dwSize = MAX_PATH; + if (RegQueryValueExA(hSubKey, lpValueName, NULL, &dwType, reinterpret_cast(result), &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) + { + RegCloseKey(hSubKey); + return result; + } + RegCloseKey(hSubKey); + } + return nullptr; // Devolver nullptr si no se pudo leer el valor +} + +bool RegKeyExists(HKEY hKeyRoot, const char* subKey) { + HKEY hKey; + if (RegOpenKeyEx(hKeyRoot, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + RegCloseKey(hKey); + return true; + } + return false; +} + +//Escribir REG_SZ en el registro +bool RegKeySet(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpValueName, LPCSTR lpData) +{ + HKEY hSubKey; + if (RegCreateKeyExA(hKey, lpSubKey, 0, NULL, 0, KEY_SET_VALUE, NULL, &hSubKey, NULL) == ERROR_SUCCESS) + { + DWORD dwSize = static_cast(strlen(lpData) + 1); + if (RegSetValueExA(hSubKey, lpValueName, 0, REG_SZ, reinterpret_cast(lpData), dwSize) == ERROR_SUCCESS) + { + RegCloseKey(hSubKey); + return true; + } + RegCloseKey(hSubKey); + } + return false; +} + +//Eliminar REG_SZ del registro +bool RegKeyDelete(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpValueName = NULL) +{ + HKEY hSubKey; + if (RegOpenKeyExA(hKey, lpSubKey, 0, KEY_SET_VALUE, &hSubKey) == ERROR_SUCCESS) + { + if (RegDeleteValueA(hSubKey, lpValueName) == ERROR_SUCCESS) + { + RegCloseKey(hSubKey); + return true; + } else if (lpValueName == NULL) { + RegDeleteKey(hKey, lpSubKey); + RegCloseKey(hSubKey); + return true; + } + RegCloseKey(hSubKey); + } + return false; +} + +// SID de Local System +static SID LocalSystem = { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_SYSTEM_RID } }; + +BOOL ImpersonateSystem() { + // Crear un snapshot de todos los hilos en el sistema + HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (hThreadSnap == INVALID_HANDLE_VALUE) { + return FALSE; + } + + THREADENTRY32 te32; + te32.dwSize = sizeof(THREADENTRY32); + + // Recuperar información del primer hilo + if (!Thread32First(hThreadSnap, &te32)) { + CloseHandle(hThreadSnap); + return FALSE; + } + + BOOL impersonated = FALSE; + + // Iterar sobre todos los hilos para encontrar uno que pertenezca a un proceso del sistema + do { + // Verificar si el hilo pertenece a un proceso del sistema + HANDLE hThread = OpenThread(THREAD_DIRECT_IMPERSONATION, FALSE, te32.th32ThreadID); + if (hThread) { + // Impersonar el hilo + if (SetThreadToken(NULL, hThread)) { + // Obtener el token del hilo + HANDLE hToken; + if (OpenThreadToken(hThread, TOKEN_QUERY, FALSE, &hToken)) { + // Verificar si el token pertenece al sistema + TOKEN_USER tokenUser; + DWORD cb; + if (GetTokenInformation(hToken, TokenUser, &tokenUser, sizeof(TOKEN_USER), &cb)) { + if (EqualSid(tokenUser.User.Sid, &LocalSystem)) { + CloseHandle(hToken); + impersonated = TRUE; + break; + } + } + CloseHandle(hToken); + } + RevertToSelf(); // Revertir la suplantación antes de cerrar el hilo + } + CloseHandle(hThread); + } + } while (Thread32Next(hThreadSnap, &te32)); + + CloseHandle(hThreadSnap); + + return impersonated; +} + +bool EnablePrivilege(DWORD processId, LPCSTR privilegeName, HANDLE hProcess = NULL) { + + TOKEN_PRIVILEGES tp; + tp.PrivilegeCount = 1; + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + if (!LookupPrivilegeValue(NULL, privilegeName, &tp.Privileges[0].Luid)) { + return false; + } + + if (!hProcess) { + hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processId); + // comprobar por ultima vez + if (!hProcess){ + return false; + } + } + + HANDLE hToken; + if (!OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken)) { + CloseHandle(hProcess); + return false; + } + + if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { + CloseHandle(hToken); + CloseHandle(hProcess); + return false; + } + + CloseHandle(hToken); + CloseHandle(hProcess); + return true; +} + +DWORD GetChildProcesses(DWORD ParentPID, DWORD* ChildPIDs) { + HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hSnapshot == INVALID_HANDLE_VALUE) { + MessageBox(0, "Error creating a process snapshot", "Error", MB_OK | MB_ICONERROR); + return 0; + } + + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + DWORD NumProcesses = 0; + + if (Process32First(hSnapshot, &pe32)) { + do { + if (pe32.th32ParentProcessID == ParentPID) { + if (NumProcesses < 64) { + ChildPIDs[NumProcesses++] = pe32.th32ProcessID; + } else { + break; + } + } + } while (Process32Next(hSnapshot, &pe32)); + } + + CloseHandle(hSnapshot); + return NumProcesses; +} + +DWORD GetPID(const char* processName) { + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return 0; + } + + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + if (!Process32First(snapshot, &entry)) { + CloseHandle(snapshot); + return 0; + } + + DWORD processId = 0; + do { + if (strcmp(entry.szExeFile, processName) == 0) { + processId = entry.th32ProcessID; + break; + } + } while (Process32Next(snapshot, &entry)); + + CloseHandle(snapshot); + return processId; +} + +DWORD ExtractPID(const char* str) { + DWORD pid = 0; + char buffer[256]; // Buffer para manipular la cadena + snprintf(buffer, sizeof(buffer), "%s", str); // Copiar la cadena original a buffer + + char* start = strstr(buffer, "(PID:"); // Buscar la cadena "(PID: " + if (start) { + start += strlen("(PID:"); // Moverse al inicio del número de PID + pid = strtoul(start, NULL, 10); // Convertir el número a DWORD + } + return pid; + +} + +void ExtractProcessName(const char* str, char* processName, size_t bufferSize) { + if (!str || !processName || bufferSize == 0) { + return; // Manejo básico de errores de parámetros nulos o tamaño de buffer cero + } + + const char* start = str; // El inicio del nombre del proceso + const char* end = strstr(str, " (PID:"); // Buscar el inicio del PID + + if (end && end > start) { + size_t length = end - start; + if (length < bufferSize - 1) { + strncpy(processName, start, length); + processName[length] = '\0'; // Asegurar que la cadena termina con '\0' + } else { + strncpy(processName, start, bufferSize - 1); + processName[bufferSize - 1] = '\0'; // Asegurar que la cadena termina con '\0' + } + } else { + // No se encontró el nombre del proceso en el formato esperado + processName[0] = '\0'; // Cadena vacía + } +} + +void CreateToolTip(HWND hwndParent, HWND hwndControl, LPSTR text) +{ + // Inicializar el tooltip + hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, + WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + hwndParent, NULL, NULL, NULL); + + // Configurar el estilo para un tooltip con fondo oscuro + SendMessage(hwndToolTip, TTM_SETTIPBKCOLOR, RGB(30, 30, 30), 0); + SendMessage(hwndToolTip, TTM_SETTIPTEXTCOLOR, RGB(255, 255, 255), 0); + SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 300); // Ancho máximo del tooltip + + // Asociar el tooltip con el control + TOOLINFO toolInfo = { 0 }; + toolInfo.cbSize = sizeof(TOOLINFO); + toolInfo.hwnd = hwndParent; + toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; + toolInfo.uId = (UINT_PTR)hwndControl; + toolInfo.lpszText = (LPSTR)text; + + // Agregar la herramienta al tooltip + SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); +} + +void UpdateToolTipText(HWND hwndControl, LPSTR text) +{ + TOOLINFO toolInfo = { 0 }; + toolInfo.cbSize = sizeof(TOOLINFO); + toolInfo.hwnd = GetParent(hwndControl); // Obtener el HWND del control padre + toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; + toolInfo.uId = (UINT_PTR)hwndControl; + toolInfo.lpszText = text; // Cambiado a text (LPSTR) + + SendMessage(hwndToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&toolInfo); +} + +BOOL GetProcessCpuSetMask(DWORD dwProcessId, PGROUP_AFFINITY cpuSetMasks, USHORT CpuSetMaskCount, PUSHORT RequiredMaskCount) +{ + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + if (hProcess == NULL) { + return FALSE; + } + + BOOL success = GetProcessDefaultCpuSetMasks(hProcess, cpuSetMasks, CpuSetMaskCount, RequiredMaskCount); + if (!success) + { + MessageBox(0, "Error getting CPU set masks", "Error", MB_OK | MB_ICONERROR); + } + + CloseHandle(hProcess); + return success; +} + +BOOL SetProcessCpuSetMask(DWORD dwProcessId, DWORD cpuBitmask) { + // Abrir el proceso con permisos para establecer información limitada + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + if (hProcess == NULL) { + return FALSE; + } + + // Si se especifica un bitmask de 0, se debe revertir los CpuSets + if (cpuBitmask == 0) { + BOOL success = SetProcessDefaultCpuSetMasks(hProcess, NULL, 0); + if (!success) { + MessageBox(0, "Error setting cpu sets", "Error", MB_OK | MB_ICONERROR); + } + CloseHandle(hProcess); + return success; + } + + // Obtener el número máximo de CPUs disponibles en el sistema + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + DWORD MAX_CPUS = sysinfo.dwNumberOfProcessors; + + GROUP_AFFINITY cpuSetMasks[1]; + cpuSetMasks[0].Mask = cpuBitmask; + cpuSetMasks[0].Group = 0; + int actualCpuSetMaskCount = 1; + + // Llamar a la función SetProcessDefaultCpuSetMasks para establecer las máscaras de CPU + BOOL success = SetProcessDefaultCpuSetMasks(hProcess, cpuSetMasks, actualCpuSetMaskCount); + if (!success) { + MessageBox(0, "Error setting cpu sets", "Error", MB_OK | MB_ICONERROR); + } + + // Cerrar el handle del proceso + CloseHandle(hProcess); + return success; +} + +void SetProcessAffinity(DWORD dwProcessId, DWORD_PTR dwProcessAffinityMask) { + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + if (hProcess == NULL) { + return; + } + + // Aplicar la máscara de afinidad de procesador al proceso + if (!SetProcessAffinityMask(hProcess, dwProcessAffinityMask)) { + MessageBox(0, "Error setting processor affinity mask", "Error", MB_OK | MB_ICONERROR); + } + CloseHandle(hProcess); +} + +DWORD_PTR GetProcessAffinity(DWORD dwProcessId) { + HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId); + if (hProcess == NULL) { + return 0; + } + + DWORD_PTR dwProcessAffinityMask = 0; + DWORD_PTR dwSystemAffinityMask = 0; + + // Obtener la máscara de afinidad de procesador del sistema + if (!GetProcessAffinityMask(hProcess, &dwProcessAffinityMask, &dwSystemAffinityMask)) { + MessageBox(0, "Error getting process affinity mask", "Error", MB_OK | MB_ICONERROR); + CloseHandle(hProcess); + return 0; + } + + CloseHandle(hProcess); + return dwProcessAffinityMask; +} + +int GetSingleCoreIndex(DWORD* CPUs, DWORD MAX_CPUS) +{ + int activeIndex = -1; // Inicializar con valor inválido + + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + if (CPUs[i] == 1) + { + // Si ya encontramos un bit activo previamente, no hay exactamente uno + if (activeIndex != -1) + return -1; + + activeIndex = i; + } + } + + return activeIndex; // Retornar el índice del bit activo o -1 si no se encontró exactamente uno +} + +void SetIdealProcessor(DWORD dwProcessId, DWORD dwIdealProcessor) +{ + HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (hSnapshot != INVALID_HANDLE_VALUE) + { + THREADENTRY32 te32; + te32.dwSize = sizeof(THREADENTRY32); + + if (Thread32First(hSnapshot, &te32)) + { + do + { + if (te32.th32OwnerProcessID == dwProcessId) + { + HANDLE hThread = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, te32.th32ThreadID); + if (hThread != NULL) + { + SetThreadIdealProcessor(hThread, dwIdealProcessor); + CloseHandle(hThread); + } + } + } while (Thread32Next(hSnapshot, &te32)); + } + + CloseHandle(hSnapshot); + } +} + +void SetProcessPriority(DWORD dwProcessId, DWORD dwPriorityClass) +{ + + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + if (!hProcess) { + return; + } + + switch (dwPriorityClass) + { + case 0: + { + dwPriorityClass = IDLE_PRIORITY_CLASS; + } + break; + case 1: + { + dwPriorityClass = BELOW_NORMAL_PRIORITY_CLASS; + } + break; + case 2: + { + dwPriorityClass = NORMAL_PRIORITY_CLASS; + } + break; + case 3: + { + dwPriorityClass = ABOVE_NORMAL_PRIORITY_CLASS; + } + break; + case 4: + { + dwPriorityClass = HIGH_PRIORITY_CLASS; + } + break; + case 5: + { + dwPriorityClass = REALTIME_PRIORITY_CLASS; + } + break; + } + + // Establecer prioridad + if (SetPriorityClass(hProcess, dwPriorityClass) == 0){ + MessageBox(0, "Error setting cpu priority", "Error", MB_OK | MB_ICONERROR); + } + +} + +DWORD GetProcessPriority(DWORD dwProcessId) +{ + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + if (!hProcess) { + return -1; + } + DWORD dwPriorityClass; + DWORD dwActualPriorityClass = GetPriorityClass(hProcess); + + switch (dwActualPriorityClass) + { + case IDLE_PRIORITY_CLASS: + { + dwPriorityClass = 0; + } + break; + case BELOW_NORMAL_PRIORITY_CLASS: + { + dwPriorityClass = 1; + } + break; + case NORMAL_PRIORITY_CLASS: + { + dwPriorityClass = 2; + } + break; + case ABOVE_NORMAL_PRIORITY_CLASS: + { + dwPriorityClass = 3; + } + break; + case HIGH_PRIORITY_CLASS: + { + dwPriorityClass = 4; + } + break; + case REALTIME_PRIORITY_CLASS: + { + dwPriorityClass = 5; + } + break; + } + return dwPriorityClass; +} + +void SetPriority(const char* PriorityType, DWORD dwProcessId, ULONG Priority){ + + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + if (!hProcess) { + return; + } + + if (strcmp(PriorityType, "MEM") == 0) { + + // Establecer prioridad de memoria + MEMORY_PRIORITY_INFORMATION MemPrio; + SecureZeroMemory(&MemPrio, sizeof(MemPrio)); + MemPrio.MemoryPriority = Priority; + + if (!SetProcessInformation(hProcess, ProcessMemoryPriority, &MemPrio, sizeof(MemPrio))){ + MessageBox(0, "Error setting memory priority", "Error", MB_OK | MB_ICONERROR); + } + + } else if (strcmp(PriorityType, "IO") == 0) { + + // Establecer prioridad E/S + IO_PRIORITY_INFORMATION IoPrio; + SecureZeroMemory(&IoPrio, sizeof(IoPrio)); + IoPrio.IoPriority = Priority; + + NTSTATUS status = NtSetInformationProcess(hProcess, ProcessIoPriority, &IoPrio, sizeof(IoPrio)); + if (!NT_SUCCESS(status)){ + MessageBox(0, "Error setting io priority", "Error", MB_OK | MB_ICONERROR); + } + } +} + +bool GetPriority(const char* PriorityType, DWORD dwProcessId, ULONG& Priority) { + + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + if (!hProcess) { + return false; + } + + if (strcmp(PriorityType, "MEM") == 0) { + // Obtener prioridad de memoria + MEMORY_PRIORITY_INFORMATION MemPrio; + SecureZeroMemory(&MemPrio, sizeof(MemPrio)); + + if (GetProcessInformation(hProcess, ProcessMemoryPriority, &MemPrio, sizeof(MemPrio))) { + Priority = MemPrio.MemoryPriority; + } else { + MessageBox(0, "Error getting memory priority", "Error", MB_OK | MB_ICONERROR); + CloseHandle(hProcess); + return false; + } + } else if (strcmp(PriorityType, "IO") == 0) { + // Obtener prioridad E/S + IO_PRIORITY_INFORMATION IoPrio; + SecureZeroMemory(&IoPrio, sizeof(IoPrio)); + + ULONG ReturnLength = 0; + NTSTATUS status = NtQueryInformationProcess(hProcess, ProcessIoPriority, &IoPrio, sizeof(IoPrio), &ReturnLength); + if (NT_SUCCESS(status)){ + Priority = IoPrio.IoPriority; + } else { + MessageBox(0, "Error getting memory priority", "Error", MB_OK | MB_ICONERROR); + } + } + + CloseHandle(hProcess); + return true; +} + +void SetProcessQos(const char* QosType, DWORD dwProcessId) +{ + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + + PROCESS_POWER_THROTTLING_STATE PowerThrottling; + SecureZeroMemory(&PowerThrottling, sizeof(PowerThrottling)); + PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION; + PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED; + + if (strcmp(QosType, "ECO") == 0) { + // Establecer estado de eficiencia (EcoQos) + PowerThrottling.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED; + + if (!SetProcessInformation(hProcess, ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling))){ + MessageBox(0, "Error setting eco qos", "Error", MB_OK | MB_ICONERROR); + } + + } else if (strcmp(QosType, "HIGH") == 0) { + // Establecer estado de maximo rendimiento (HighQos) + PowerThrottling.StateMask = 0x0; + + if (!SetProcessInformation(hProcess, ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling))){ + MessageBox(0, "Error setting high qos", "Error", MB_OK | MB_ICONERROR); + } + } +} + +void GetProcessQos(DWORD dwProcessId, ULONG& Qos) { + + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + if (!hProcess) { + return; + } + PROCESS_POWER_THROTTLING_STATE PowerThrottling; + SecureZeroMemory(&PowerThrottling, sizeof(PowerThrottling)); + PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION; + + NTSTATUS status = ZwQueryInformationProcess(hProcess, ProcPowerThrottlingState, &PowerThrottling, sizeof(PowerThrottling), NULL); + if (NT_SUCCESS(status)){ + Qos = PowerThrottling.StateMask; + } + CloseHandle(hProcess); + +} + +BOOL IsSuspended(DWORD dwProcessId) { + ULONG bufferSize = 0; + NTSTATUS status = ZwQuerySystemInformation(SystemProcessInformation, NULL, 0, &bufferSize); + if (status != STATUS_INFO_LENGTH_MISMATCH) { + MessageBox(0, "Error obtaining initial buffer size", "Error", MB_OK | MB_ICONERROR); + return FALSE; // Error al obtener tamaño inicial + } + + PVOID buffer = NULL; + do { + buffer = malloc(bufferSize); + if (!buffer) { + MessageBox(0, "Error allocating memory", "Error", MB_OK | MB_ICONERROR); + return FALSE; // Error al asignar memoria + } + + status = ZwQuerySystemInformation(SystemProcessInformation, buffer, bufferSize, NULL); + if (status == STATUS_INFO_LENGTH_MISMATCH) { + free(buffer); + buffer = NULL; + } + } while (status == STATUS_INFO_LENGTH_MISMATCH); + + if (!NT_SUCCESS(status)) { + MessageBox(0, "Error obtaining process information", "Error", MB_OK | MB_ICONERROR); + free(buffer); + return FALSE; // Error al obtener información de procesos + } + + BOOL anyThreadSuspended = FALSE; + PSYSTEM_PROCESS_INFORMATION currentProcess = (PSYSTEM_PROCESS_INFORMATION)buffer; + + while (TRUE) { + if (HandleToUlong(currentProcess->UniqueProcessId) == dwProcessId) { + PSYSTEM_THREAD_INFORMATION threadInfo = (PSYSTEM_THREAD_INFORMATION)((PCHAR)currentProcess + sizeof(SYSTEM_PROCESS_INFORMATION)); + + for (ULONG i = 0; i < currentProcess->NumberOfThreads; i++) { + if (threadInfo->ThreadState == StateWait && threadInfo->WaitReason == Suspended) { + anyThreadSuspended = TRUE; + break; + } + threadInfo++; + } + break; + } + + if (currentProcess->NextEntryOffset == 0) break; + currentProcess = (PSYSTEM_PROCESS_INFORMATION)((PCHAR)currentProcess + currentProcess->NextEntryOffset); + } + + free(buffer); + return anyThreadSuspended; +} + +void _SR(const char* ActionType, DWORD dwProcessId) { + + HANDLE hProcess = OpenProcess(PROCESS_SUSPEND_RESUME, FALSE, dwProcessId); + + if (strcmp(ActionType, "SUSPEND") == 0) { + NtSuspendProcess(hProcess); + } else if (strcmp(ActionType, "RESUME") == 0) { + NtResumeProcess(hProcess); + } +} + +DWORD GetProcInfo(DWORD dwProcessId, LPSTR lpPath, DWORD nSize) +{ + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId); + if (hProcess == NULL) { + return 0; + } + + DWORD dwLength = nSize; + if (!QueryFullProcessImageName(hProcess, 0, lpPath, &dwLength)) { + CloseHandle(hProcess); + return 0; + } + + CloseHandle(hProcess); + return dwLength; +} + +void CheckMenuItemProcess(HMENU hMenu, char* ProcessName, DWORD dwProcessId){ + + // Construir la clave del registro + char registryKey[MAX_PATH]; + snprintf(registryKey, sizeof(registryKey), "Software\\SetProcess\\%s", ProcessName); + + EnablePrivilege(dwProcessId, SE_INC_BASE_PRIORITY_NAME); + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + + // Marcar el ítem de menú correspondiente según la prioridad de CPU + DWORD dwPriorityClass = GetProcessPriority(dwProcessId); + UINT priorityClassId; + + switch (dwPriorityClass) + { + case 0: + { + priorityClassId = IDM_CPU_PRIORITY_IDLE; + } + break; + case 1: + { + priorityClassId = IDM_CPU_PRIORITY_BELOW_NORMAL; + } + break; + case 2: + { + priorityClassId= IDM_CPU_PRIORITY_NORMAL; + } + break; + case 3: + { + priorityClassId = IDM_CPU_PRIORITY_ABOVE_NORMAL; + } + break; + case 4: + { + priorityClassId = IDM_CPU_PRIORITY_HIGH; + } + + break; + case 5: + { + priorityClassId = IDM_CPU_PRIORITY_REALTIME; + } + break; + } + + if (priorityClassId != 0) + { + CheckMenuItem(hMenu, priorityClassId, MF_BYCOMMAND | MF_CHECKED); + } + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass") != nullptr) { + CheckMenuItem(hMenu, IDM_CPU_PRIORITY_SAVE, MF_BYCOMMAND | MF_CHECKED); + } + + // Marcar el ítem de menú correspondiente según la prioridad de memoria + ULONG memPriority; + GetPriority("MEM", dwProcessId, memPriority); + UINT memPriorityId; + switch (memPriority) + { + case 1: + { + memPriorityId = IDM_MEMORY_PRIORITY_VERYLOW; + } + break; + case 2: + { + memPriorityId = IDM_MEMORY_PRIORITY_LOW; + } + break; + case 3: + { + memPriorityId = IDM_MEMORY_PRIORITY_MEDIUM; + } + break; + case 4: + { + memPriorityId = IDM_MEMORY_PRIORITY_BELOWNORMAL; + } + break; + case 5: + { + memPriorityId = IDM_MEMORY_PRIORITY_NORMAL; + } + break; + } + + if (memPriorityId != 0) + { + CheckMenuItem(hMenu, memPriorityId, MF_BYCOMMAND | MF_CHECKED); + } + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority") != nullptr) { + CheckMenuItem(hMenu, IDM_MEMORY_PRIORITY_SAVE, MF_BYCOMMAND | MF_CHECKED); + } + + // Marcar el ítem de menú correspondiente según la prioridad de memoria + ULONG ioPriority; + GetPriority("IO", dwProcessId, ioPriority); + UINT ioPriorityId; + switch (ioPriority) + { + case 0: + { + ioPriorityId = IDM_IO_PRIORITY_VERYLOW; + } + break; + case 1: + { + ioPriorityId = IDM_IO_PRIORITY_LOW; + } + break; + case 2: + { + ioPriorityId = IDM_IO_PRIORITY_NORMAL; + } + break; + case 3: + { + ioPriorityId = IDM_IO_PRIORITY_HIGH; + } + break; + } + + if (ioPriorityId != 0) + { + CheckMenuItem(hMenu, ioPriorityId, MF_BYCOMMAND | MF_CHECKED); + } + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority") != nullptr) { + CheckMenuItem(hMenu, IDM_IO_PRIORITY_SAVE, MF_BYCOMMAND | MF_CHECKED); + } + + // 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 (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost") != nullptr) { + CheckMenuItem(hMenu, IDM_CPU_PRIORITY_BOOST_SAVE, MF_BYCOMMAND | MF_CHECKED); + } + + //Verificar Qos + ULONG Qos; + GetProcessQos(dwProcessId, Qos); + + if (Qos == 0) { + CheckMenuItem(hMenu, IDM_QOS_HIGHQOS, MF_BYCOMMAND | MF_CHECKED); + if (GetProcessPriority(dwProcessId) == 0) { + SetProcessPriority(dwProcessId, 2); + } + } else if (Qos == PROCESS_POWER_THROTTLING_EXECUTION_SPEED) { + CheckMenuItem(hMenu, IDM_QOS_ECOQOS, MF_BYCOMMAND | MF_CHECKED); + SetProcessPriority(dwProcessId, 0); + + + } + + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "EcoQos") != nullptr) { + CheckMenuItem(hMenu, IDM_QOS_SAVE, MF_BYCOMMAND | MF_CHECKED); + } else if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "HighQos") != nullptr) { + CheckMenuItem(hMenu, IDM_QOS_SAVE, MF_BYCOMMAND | MF_CHECKED); + } + + if (IsSuspended(dwProcessId)) { + ModifyMenu(hMenu, IDM_SUSPEND_RESUME, MF_BYCOMMAND | MF_STRING, IDM_SUSPEND_RESUME, "Resume"); + } else { + ModifyMenu(hMenu, IDM_SUSPEND_RESUME, MF_BYCOMMAND | MF_STRING, IDM_SUSPEND_RESUME, "Suspend"); + } + +} + +void LoadConfigProcess(const char* ProcessName, DWORD dwProcessId) +{ + char registryKey[MAX_PATH]; + snprintf(registryKey, sizeof(registryKey), "Software\\SetProcess\\%s", ProcessName); + + EnablePrivilege(dwProcessId, SE_INC_BASE_PRIORITY_NAME); + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + + // Cargar CpuSets + char* cpuSetMask = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "CpuSets"); + + if (cpuSetMask != nullptr) + { + DWORD newCpuBitmask = 0; + for (DWORD i = 0; i < strlen(cpuSetMask); ++i) { + if (cpuSetMask[i] == '1') { + newCpuBitmask |= (1 << i); + } + } + SetProcessCpuSetMask(dwProcessId, newCpuBitmask); + } + + // Cargar IdealProcessor + char* IdealProcStr = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IdealProc"); + if (IdealProcStr != nullptr) + { + DWORD IdealProc = atoi(IdealProcStr); + SetIdealProcessor(dwProcessId, IdealProc); + } + + // Cargar AffinityMask + char* affinityMask = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "AffinityMask"); + + if (affinityMask != nullptr) + { + DWORD_PTR dwProcessAffinityMask = 0; + for (DWORD i = 0; i < strlen(affinityMask); ++i) { + if (affinityMask[i] == '1') { + dwProcessAffinityMask |= (1 << i); + } + } + SetProcessAffinity(dwProcessId, dwProcessAffinityMask); + } + + // Cargar PriorityBoost + char* priorityBoost = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityBoost"); + if (priorityBoost != nullptr) { + HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId); + SetProcessPriorityBoost(hProcess, FALSE); + } + + // Cargar PriorityClass + char* Priority = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "PriorityClass"); + if (Priority != nullptr) { + EnablePrivilege(dwProcessId, SE_DEBUG_NAME); + SetProcessPriority(dwProcessId, atoi(Priority)); + } + + // Cargar MemPriority + char* memPriority = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "MemoryPriority"); + if (memPriority != nullptr) { + SetPriority("MEM", dwProcessId, atoi(memPriority)); + } + + // Cargar IoPriority + char* ioPriority = RegKeyQuery(HKEY_CURRENT_USER, registryKey, "IoPriority"); + if (ioPriority != nullptr) { + SetPriority("IO", dwProcessId, atoi(ioPriority)); + } + + // Cargar EcoQos + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "EcoQos") != nullptr) { + SetProcessQos("ECO", dwProcessId); + } + + // Cargar HighQos + if (RegKeyQuery(HKEY_CURRENT_USER, registryKey, "HighQos") != nullptr) { + SetProcessQos("HIGH", dwProcessId); + } +} + +void AddProcessToListBox(HWND hListBox, const TCHAR* processName, DWORD dwProcessId) { + char buffer[MAX_PATH]; + _snprintf_s(buffer, sizeof(buffer), _TRUNCATE, "%s (PID:%lu)", processName, dwProcessId); + SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer); +} + +void PopulateListBox(HWND hListBox) { + SendMessage(hListBox, LB_RESETCONTENT, 0, 0); + + HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hSnapshot == INVALID_HANDLE_VALUE) { + return; + } + + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + if (Process32First(hSnapshot, &pe32)) { + do { + // Añadir procesos al ListBox + AddProcessToListBox(hListBox, pe32.szExeFile, pe32.th32ProcessID); + + // Leer la configuración del registro para este proceso + LoadConfigProcess(pe32.szExeFile, pe32.th32ProcessID); + } while (Process32Next(hSnapshot, &pe32)); + } + + CloseHandle(hSnapshot); +} + +void ShowListBoxMenu(HWND hListBox, char* ProcessName, DWORD dwProcessId, int x, int y) +{ + HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_CONTEXT_MENU)); + if (hMenu != NULL) + { + HMENU hPopupMenu = GetSubMenu(hMenu, 0); + CheckMenuItemProcess(hMenu, ProcessName, dwProcessId); + TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, GetParent(hListBox), NULL); + DestroyMenu(hMenu); + } +} + +// Declaración del trayicon +NOTIFYICONDATA nid; +bool isIconVisible = false; + +//ShowTrayMenu +void ShowTrayMenu(HWND hWnd) +{ + //obtener posición del puntero (x,y) + POINT pt; + GetCursorPos(&pt); + + HMENU hMenu = CreatePopupMenu(); + AppendMenu(hMenu, MF_STRING, IDM_EXIT, "Exit"); + + //poner en primer plano la ventana actual y centrar el menú + SetForegroundWindow(hWnd); + TrackPopupMenu(hMenu, TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_NONOTIFY | TPM_LEFTBUTTON, pt.x, pt.y, 0, hWnd, NULL); + DestroyMenu(hMenu); +} + +HWINEVENTHOOK g_hookID; +HWND HWNDPrev = NULL; +void CALLBACK WinEventProc( + HWINEVENTHOOK hWinEventHook, + DWORD dwEvent, + HWND hwnd, + LONG idObject, + LONG idChild, + DWORD dwEventThread, + DWORD dwmsEventTime +) + +{ + if (dwEvent == EVENT_SYSTEM_FOREGROUND && hwnd != NULL && idObject == OBJID_WINDOW && hwnd != HWNDPrev || dwEvent == EVENT_OBJECT_CREATE && hwnd != NULL && idObject == OBJID_WINDOW && hwnd != HWNDPrev) + { + + if (idChild != CHILDID_SELF) { + return; + } + + DWORD dwProcessId = 0; + GetWindowThreadProcessId(hwnd, &dwProcessId); + + // Obtener el nombre del proceso asociado con el ID del proceso + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId); + if (hProcess) + { + TCHAR szProcessName[MAX_PATH]; + if (GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName))) + { + char registryKey[MAX_PATH]; + snprintf(registryKey, sizeof(registryKey), "Software\\SetProcess\\%s", szProcessName); + if (RegKeyExists(HKEY_CURRENT_USER, registryKey)) + { + LoadConfigProcess(szProcessName, dwProcessId); + CloseHandle(hProcess); + return; + } + } + CloseHandle(hProcess); + } + HWNDPrev = hwnd; + } +} + +INT_PTR CALLBACK BitMaskDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static DWORD* pCPUs = nullptr; + static DWORD MAX_CPUS = 0; // Tamaño máximo de CPUs, ajustar según tu necesidad + + switch (message) + { + case WM_INITDIALOG: + { + // Asignar pCPUs desde lParam + pCPUs = reinterpret_cast(lParam); + + if (!pCPUs) + { + EndDialog(hDlg, IDCANCEL); + return (INT_PTR)FALSE; + } + + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + MAX_CPUS = sysinfo.dwNumberOfProcessors; + + for (DWORD i = 0; i < 64; ++i) + { + if (i < MAX_CPUS) { + CheckDlgButton(hDlg, IDC_CPU_0 + i, pCPUs[i] == 1 ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(GetDlgItem(hDlg, IDC_CPU_0 + i), TRUE); + } else { + EnableWindow(GetDlgItem(hDlg, IDC_CPU_0 + i), FALSE); + } + } + return (INT_PTR)TRUE; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_SAVE_BITMASK: + { + // Leer el estado de los checkboxes y guardar en pCPUs + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + pCPUs[i] = IsDlgButtonChecked(hDlg, IDC_CPU_0 + i) == BST_CHECKED ? 1 : 0; + } + + EndDialog(hDlg, 0); + return (INT_PTR)TRUE; + } + + case IDC_CHECK_ALL: + { + // Marcar todos los checkboxes + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + CheckDlgButton(hDlg, IDC_CPU_0 + i, BST_CHECKED); + } + + return (INT_PTR)TRUE; + } + + case IDC_UNCHECK: + { + // Desmarcar todos los checkboxes + for (DWORD i = 0; i < MAX_CPUS; ++i) + { + CheckDlgButton(hDlg, IDC_CPU_0 + i, BST_UNCHECKED); + } + + return (INT_PTR)TRUE; + } + } + break; + } + return (INT_PTR)FALSE; +} + +void ShowBitMaskDialog(HWND hParent, DWORD* CPUs) +{ + DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(DLG_BITMASK), hParent, BitMaskDlgProc, reinterpret_cast(CPUs)); +} + diff --git a/SetProcessGui/SetProcessGui.ico b/SetProcessGui/SetProcessGui.ico new file mode 100644 index 0000000000000000000000000000000000000000..da6e5543959028c414198c27d13353b2da053e71 GIT binary patch literal 4286 zcmeI0YfRQv9LLWC_y7+G$X%{p0TH=~h#KG(hcBEmaWjOijWQ`A+R|)=m(5pA!sZL- z+Ds$N>8$27tb8G+U72&vSx!xJQ%dHf%eaye(4km^?uUeg7?;cCSF zXM5!aTMQpQ+(bu5kM?*xuS3m`L90iM7?CDDjrR6-Z;a@!1y>*2ec;&H+1cruHf@@f z8|nd86CNJEBp@Kb>Ph!egxmw<7fMefEiKJNMn)?BjG&;P3(^I{-LSB*8u91MnWJgQ zK`bUNE-r=I9Tj#5KMDhII6UPR`9yMN)~s1$va_?zp+kpU)TG7HLFO}X4Iepjq^YQ= zu)ZrRD;1~FUQ|?+#Vp)flQ-c{26HVkO<+0e*wRc~r{Og!CghTs4L!zvG|Jk|W^J;x`Wh*8i|RCs_Q;s5KjDs>RdV_BO}ACT)9&IRr~YE z$Kgx&l_hFwpm=JQ2VZ?+?=$2~Qc_YBdOu+MK4+s^Hg%_DWo4PUbLUzY)JFPQ=w4DU zke6qKt+%(=^8Nke7Z(YZ=RD|*daxhhE_Ej-C%dtiSzTT2qHiZ-^LK3jC_Q1GJbALC zrnrpWJvtNUzpor%Yn23gdU~wfqx?^qGR17!vc>iWasI^p5KWGAuyu^{n8vyc|99bi z#n}z>&8rtg|ALxt>aW2%ZC$x?#d7@p6MLNUtf6zleHKS=eh*zH-b`{=1^>405q{_P z$A8v|f5wa%R#y+jKWo-3#c#m8qd)!z@vdIIs>%5IKSyrMvE4}B>eV}}OTc~v`hvX* z<_%!E$@~`gOeC>)VfP;OUnYCy<>hA5q)BG}{Q3H6&{6#}z&)Rm3^oG)lA^s)1UiK zbvIHg>st>$|LT8zJ{t8FK8``1*jkFsm!SRp{v2Kf`8-T)oA9}c^(V4Vj6cI~W`8!M zK7WDpe;jk-T@XI78204C4*9RIulJrm)sY@o{sOVJi@1KH*Txa2d|qSk5Z^H|tPfzT zoBAw7Cz;>7$?xC70o`SNyMNt>zi+{8KX&xZQ&m;vxc^uD^3PDesCILRdHc9=!tM|y` z2f|%iTB^xAGBY!s{C|Ypd18;(Ii5a!y3xC0!h{JXKR;jbxykifuw-M>t6x}HXzx7T zd(xRYb*d3|QUCWu5_t8l*eR_3{)>x??fE2EyYPPv+u2K(E)6OxD|7qO%$YOYd^3k| zuMXJvm2uYiaEoecYJ$Lvd&jW*GJku7@V+vQjg5|LJF6z#Pxig0 z4eIUTyD{j0A`Uf8}#1?4@oa&UvdQ)HxvoqJ(x@|@`F(%HX|LU{{Z+4GhP4y literal 0 HcmV?d00001 diff --git a/SetProcessGui/SetProcessGui.layout b/SetProcessGui/SetProcessGui.layout new file mode 100644 index 0000000..ab12a49 --- /dev/null +++ b/SetProcessGui/SetProcessGui.layout @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/SetProcessGui/SetProcessGui.rc b/SetProcessGui/SetProcessGui.rc new file mode 100644 index 0000000..6308448 --- /dev/null +++ b/SetProcessGui/SetProcessGui.rc @@ -0,0 +1,185 @@ +// Generated by ResEdit 1.5.10 +// Copyright (C) 2006-2012 +// http://www.resedit.net + +#include +#include +#include "SetProcessGui.h" + + +// +// Dialog resources +// +DLG_MAIN DIALOG 0, 0, 200, 170 +STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_DLGFRAME +CAPTION "SetProcess | LuSlower" +FONT 8, "Ms Shell Dlg" +//controls +BEGIN +LISTBOX IDC_LISTP, 5, 5, 190, 150, LBS_STANDARD | WS_TABSTOP +PUSHBUTTON "Refresh", IDC_REFRESH, 155, 154, 40, 12 +CHECKBOX "Start With Windows (hidden)", _START, 5, 155, 110, 10, BS_AUTOCHECKBOX +END + +// +// Context menu +// +IDR_CONTEXT_MENU MENU +BEGIN + POPUP "Configuración" + BEGIN + MENUITEM "CpuSets", IDM_CPUSETS + MENUITEM SEPARATOR + MENUITEM "Ideal Processor", IDM_IDEAL_PROCESSOR + MENUITEM SEPARATOR + MENUITEM "Affinity", IDM_AFFINITY + MENUITEM SEPARATOR + POPUP "CPU Priority Boost" + BEGIN + MENUITEM "Boost", IDM_CPU_PRIORITY_BOOST + MENUITEM "Save to registry", IDM_CPU_PRIORITY_BOOST_SAVE + END + MENUITEM SEPARATOR + POPUP "CPU Priority" + BEGIN + MENUITEM "Idle", IDM_CPU_PRIORITY_IDLE + MENUITEM "Below Normal", IDM_CPU_PRIORITY_BELOW_NORMAL + MENUITEM "Normal", IDM_CPU_PRIORITY_NORMAL + MENUITEM "Above Normal", IDM_CPU_PRIORITY_ABOVE_NORMAL + MENUITEM "High", IDM_CPU_PRIORITY_HIGH + MENUITEM "Realtime", IDM_CPU_PRIORITY_REALTIME + MENUITEM "Save to registry", IDM_CPU_PRIORITY_SAVE + END + MENUITEM SEPARATOR + POPUP "Memory Priority" + BEGIN + MENUITEM "Very Low", IDM_MEMORY_PRIORITY_VERYLOW + MENUITEM "Low", IDM_MEMORY_PRIORITY_LOW + MENUITEM "Medium", IDM_MEMORY_PRIORITY_MEDIUM + MENUITEM "Below Normal", IDM_MEMORY_PRIORITY_BELOWNORMAL + MENUITEM "Normal", IDM_MEMORY_PRIORITY_NORMAL + MENUITEM "Save to registry", IDM_MEMORY_PRIORITY_SAVE + END + MENUITEM SEPARATOR + POPUP "I/O Priority" + BEGIN + MENUITEM "Very Low", IDM_IO_PRIORITY_VERYLOW + MENUITEM "Low", IDM_IO_PRIORITY_LOW + MENUITEM "Normal", IDM_IO_PRIORITY_NORMAL + MENUITEM "High", IDM_IO_PRIORITY_HIGH + MENUITEM "Save to registry", IDM_IO_PRIORITY_SAVE + END + MENUITEM SEPARATOR + POPUP "QoS" + BEGIN + MENUITEM "EcoQoS (Efficiency Mode)", IDM_QOS_ECOQOS + MENUITEM "HighQoS (High Performance Mode)", IDM_QOS_HIGHQOS + MENUITEM "Save to registry", IDM_QOS_SAVE + END + MENUITEM SEPARATOR + MENUITEM "Suspend", IDM_SUSPEND_RESUME + MENUITEM SEPARATOR + MENUITEM "Reset Config", IDM_RESET + END +END + + +DLG_BITMASK DIALOGEX 0, 0, 350, 110 +STYLE DS_SETFONT | WS_POPUP | WS_CAPTION +CAPTION "Select Processors BitMask" +FONT 8, "MS Shell Dlg" +BEGIN + CHECKBOX "CPU 0", IDC_CPU_0, 10, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 1", IDC_CPU_1, 10, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 2", IDC_CPU_2, 10, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 3", IDC_CPU_3, 10, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 4", IDC_CPU_4, 10, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 5", IDC_CPU_5, 10, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 6", IDC_CPU_6, 10, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 7", IDC_CPU_7, 10, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 8", IDC_CPU_8, 10, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 9", IDC_CPU_9, 10, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 10", IDC_CPU_10, 60, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 11", IDC_CPU_11, 60, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 12", IDC_CPU_12, 60, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 13", IDC_CPU_13, 60, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 14", IDC_CPU_14, 60, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 15", IDC_CPU_15, 60, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 16", IDC_CPU_16, 60, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 17", IDC_CPU_17, 60, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 18", IDC_CPU_18, 60, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 19", IDC_CPU_19, 60, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 20", IDC_CPU_20, 110, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 21", IDC_CPU_21, 110, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 22", IDC_CPU_22, 110, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 23", IDC_CPU_23, 110, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 24", IDC_CPU_24, 110, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 25", IDC_CPU_25, 110, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 26", IDC_CPU_26, 110, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 27", IDC_CPU_27, 110, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 28", IDC_CPU_28, 110, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 29", IDC_CPU_29, 110, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 30", IDC_CPU_30, 160, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 31", IDC_CPU_31, 160, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 32", IDC_CPU_32, 160, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 33", IDC_CPU_33, 160, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 34", IDC_CPU_34, 160, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 35", IDC_CPU_35, 160, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 36", IDC_CPU_36, 160, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 37", IDC_CPU_37, 160, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 38", IDC_CPU_38, 160, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 39", IDC_CPU_39, 160, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 40", IDC_CPU_40, 210, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 41", IDC_CPU_41, 210, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 42", IDC_CPU_42, 210, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 43", IDC_CPU_43, 210, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 44", IDC_CPU_44, 210, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 45", IDC_CPU_45, 210, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 46", IDC_CPU_46, 210, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 47", IDC_CPU_47, 210, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 48", IDC_CPU_48, 210, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 49", IDC_CPU_49, 210, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 50", IDC_CPU_50, 260, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 51", IDC_CPU_51, 260, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 52", IDC_CPU_52, 260, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 52", IDC_CPU_53, 260, 35, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 54", IDC_CPU_54, 260, 45, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 55", IDC_CPU_55, 260, 55, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 56", IDC_CPU_56, 260, 65, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 57", IDC_CPU_57, 260, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 58", IDC_CPU_58, 260, 75, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 59", IDC_CPU_59, 260, 85, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 60", IDC_CPU_60, 260, 95, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 61", IDC_CPU_61, 310, 5, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 62", IDC_CPU_62, 310, 15, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + CHECKBOX "CPU 63", IDC_CPU_63, 310, 25, 50, 10, BS_AUTOCHECKBOX | WS_TABSTOP + PUSHBUTTON "ChkAll", IDC_CHECK_ALL, 310, 65, 30, 12 + PUSHBUTTON "UnChk", IDC_UNCHECK, 310, 80, 30, 12 + PUSHBUTTON "Save", IDC_SAVE_BITMASK, 310, 95, 30, 12 +END + +// +// Manifest resources +// +LANGUAGE 0, SUBLANG_NEUTRAL +1 RT_MANIFEST ".\\manifest.xml" +IDI_ICON ICON "SetProcessGui.ico" +VS_VERSION_INFO VERSIONINFO +BEGIN + BLOCK "StringFileInfo" + { + BLOCK "040904E4" + { + VALUE "CompanyName", "LuSlower Software" + VALUE "FileDescription", "SetProcess" + VALUE "FileVersion", "0.0.0.0" + VALUE "LegalCopyright", "Copyright © LuSlower" + VALUE "ProductName", "SetProcess" + VALUE "ProductVersion", "0.0.0.0" + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation", 0x409, 1252 + } +END diff --git a/SetProcessGui/manifest.xml b/SetProcessGui/manifest.xml new file mode 100644 index 0000000..2e4184e --- /dev/null +++ b/SetProcessGui/manifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + +