From 782cbb3c7437ab8bd2f8be553357c49effa01044 Mon Sep 17 00:00:00 2001 From: Milan Herbig Date: Wed, 16 Oct 2024 20:34:56 +0200 Subject: [PATCH] Fixed execution of task manager on Windows 11 24H2 --- mods/taskbar-empty-space-clicks.wh.cpp | 27 ++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mods/taskbar-empty-space-clicks.wh.cpp b/mods/taskbar-empty-space-clicks.wh.cpp index 7806bb4ec..054247eea 100644 --- a/mods/taskbar-empty-space-clicks.wh.cpp +++ b/mods/taskbar-empty-space-clicks.wh.cpp @@ -2,7 +2,7 @@ // @id taskbar-empty-space-clicks // @name Click on empty taskbar space // @description Trigger custom action when empty space on a taskbar is double/middle clicked -// @version 1.4 +// @version 1.5 // @author m1lhaus // @github https://github.com/m1lhaus // @include explorer.exe @@ -1754,12 +1754,22 @@ void OpenTaskManager(HWND taskbarhWnd) { LOG_TRACE(); - LOG_INFO(L"Sending OpenTaskManager message"); - // https://www.codeproject.com/Articles/14380/Manipulating-The-Windows-Taskbar - if (SendMessage(taskbarhWnd, WM_COMMAND, MAKELONG(420, 0), 0) != 0) - { - LOG_ERROR(L"Failed to send OpenTaskManager message"); - } + LOG_INFO(L"Opening Taskmgr.exe using ShellExecuteEx"); + std::wstring taskmgrPath = L"C:\\Windows\\System32\\Taskmgr.exe"; + + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.lpVerb = L"open"; // Use "runas" to explicitly request elevation + sei.lpFile = taskmgrPath.c_str(); + sei.nShow = SW_SHOW; + + if (!ShellExecuteEx(&sei)) + { + DWORD error = GetLastError(); + if (error != ERROR_CANCELLED) // User declined the elevation. + { + LOG_ERROR(L"Failed to start process taskmgr.exe with error code: %d", error); + } + } } void ToggleVolMuted() @@ -1912,7 +1922,8 @@ void StartProcess(const std::wstring &command) if (!CreateProcess(NULL, (LPWSTR)command.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { - LOG_ERROR(L"Failed to start process - CreateProcess failed!"); + DWORD error = GetLastError(); + LOG_ERROR(L"Failed to start process - CreateProcess failed with error code: %d", error); } else {