Skip to content

Commit

Permalink
Fixed execution of task manager on Windows 11 24H2
Browse files Browse the repository at this point in the history
  • Loading branch information
m1lhaus committed Oct 16, 2024
1 parent eb6dedd commit 782cbb3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions mods/taskbar-empty-space-clicks.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 782cbb3

Please sign in to comment.