Skip to content

Commit

Permalink
Custom Shutdown Dialog 1.1.0 (#1226)
Browse files Browse the repository at this point in the history
- Add ability to override logoff dialog (used in Windows XP Explorer)
  • Loading branch information
aubymori authored Nov 10, 2024
1 parent 699e3b8 commit f7f83c3
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions mods/custom-shutdown-dialog.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id custom-shutdown-dialog
// @name Custom Shutdown Dialog
// @description Override the classic shutdown dialog in Explorer with your own
// @version 1.0.1
// @version 1.1.0
// @author aubymori
// @github https://github.com/aubymori
// @include explorer.exe
Expand All @@ -14,23 +14,34 @@
# Custom Shutdown Dialog
Override the classic shutdown dialog in Explorer
which is invoked with `ALT`+`F4` with your own program.
This also lets you override the action of the "Log Off" button
in Windows XP's Explorer, which on Windows 10 normally instantly logs
the user out.
*/
// ==/WindhawkModReadme==

// ==WindhawkModSettings==
/*
- exe: C:\Classic\ClassicShutdown\ClassicShutdown.exe
$name: Executable
$description: Path to executable to open instead of dialog.
$name: Shutdown executable
$description: Path to executable to open instead of shutdown dialog.
- args: /style classic
$name: Arguments
$description: Arguments to pass to the executable, if any.
$name: Shutdown arguments
$description: Arguments to pass to the shutdown executable, if any.
- logoffexe: C:\Classic\ClassicShutdown\ClassicShutdown.exe
$name: Logoff executable
$description: Path to executable to open instead of logoff dialog.
- logoffargs: /logoff /style classic
$name: Logoff arguments
$description: Arguments to pass to the logoff executable, if any.
*/
// ==/WindhawkModSettings==

#include <windhawk_utils.h>

WindhawkUtils::StringSetting g_szExe, g_szArgs;
WindhawkUtils::StringSetting g_szShutdownExe, g_szShutdownArgs;
WindhawkUtils::StringSetting g_szLogoffExe, g_szLogoffArgs;

__int64 (*_ShutdownDialogEx_orig)(HWND, int, int, UINT);
__int64 _ShutdownDialogEx_hook(
Expand All @@ -43,14 +54,27 @@ __int64 _ShutdownDialogEx_hook(
ShellExecuteW(
hWndParent,
L"open",
g_szExe,
g_szArgs,
g_szShutdownExe,
g_szShutdownArgs,
NULL,
SW_NORMAL
);
return 0;
}

void (*LogoffWindowsDialog_orig)(HWND);
void LogoffWindowsDialog_hook(HWND hWndParent)
{
ShellExecuteW(
hWndParent,
L"open",
g_szLogoffExe,
g_szLogoffArgs,
NULL,
SW_NORMAL
);
}

WindhawkUtils::SYMBOL_HOOK shutdownuxDllHooks[] = {
{
{
Expand All @@ -60,12 +84,25 @@ WindhawkUtils::SYMBOL_HOOK shutdownuxDllHooks[] = {
_ShutdownDialogEx_hook,
false
}
};\

WindhawkUtils::SYMBOL_HOOK shell32DllHooks[] = {
{
{
L"LogoffWindowsDialog"
},
&LogoffWindowsDialog_orig,
LogoffWindowsDialog_hook,
false
}
};

void LoadSettings(void)
{
g_szExe = WindhawkUtils::StringSetting::make(L"exe");
g_szArgs = WindhawkUtils::StringSetting::make(L"args");
g_szShutdownExe = WindhawkUtils::StringSetting::make(L"exe");
g_szShutdownArgs = WindhawkUtils::StringSetting::make(L"args");
g_szLogoffExe = WindhawkUtils::StringSetting::make(L"logoffexe");
g_szLogoffArgs = WindhawkUtils::StringSetting::make(L"logoffargs");
}

BOOL Wh_ModInit(void)
Expand All @@ -89,6 +126,23 @@ BOOL Wh_ModInit(void)
return FALSE;
}

HMODULE hShell32 = LoadLibraryW(L"shell32.dll");
if (!hShell32)
{
Wh_Log(L"Failed to load shell32.dll");
return FALSE;
}

if (!WindhawkUtils::HookSymbols(
hShell32,
shell32DllHooks,
ARRAYSIZE(shell32DllHooks)
))
{
Wh_Log(L"Failed to hook LogoffWindowsDialog");
return FALSE;
}

return TRUE;
}

Expand Down

0 comments on commit f7f83c3

Please sign in to comment.