-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Restart explorer the "official" graceful way #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
b76692a to
449a089
Compare
449a089 to
ef06557
Compare
aa74b5d to
046d4f3
Compare
…a/systeminformer into gentle-explorer-restart
046d4f3 to
00e05cc
Compare
| GetClassName(taskbarWindow, windowClassName, RTL_NUMBER_OF(windowClassName)); | ||
| if (PhEqualStringZ(windowClassName, L"Shell_TrayWnd", FALSE)) | ||
| { | ||
| postToTaskbar = !PostMessage(taskbarWindow, WM_USER + 0x1B4, 0, 0); // exit Explorer official way (Dart Vanya) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which OS are these values from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't send private window messages since the identifiers can change. The menu this references was removed on Windows 11.
|
Here's a fully documented and official method for restarting the Explorer process: BOOL CALLBACK EnumWindowCallback(
_In_ HWND WindowHandle,
_In_ LPARAM Context
)
{
ULONG processId = 0;
GetWindowThreadProcessId(WindowHandle, &processId);
if (processId == (ULONG)Context && IsWindowVisible(WindowHandle))
{
ULONG_PTR result = 0;
if (SendMessageTimeout(
WindowHandle,
WM_QUERYENDSESSION,
0,
ENDSESSION_CLOSEAPP,
SMTO_ABORTIFHUNG | SMTO_BLOCK | SMTO_ERRORONEXIT,
5000,
&result
))
{
if (result)
{
SendMessageTimeout(
WindowHandle,
WM_ENDSESSION,
TRUE,
ENDSESSION_LOGOFF,
SMTO_ABORTIFHUNG | SMTO_BLOCK | SMTO_ERRORONEXIT,
5000,
&result
);
}
}
}
return TRUE;
}
VOID CloseExplorer()
{
ULONG processId = 0;
GetWindowThreadProcessId(GetShellWindow(), &processId);
EnumWindows(EnumWindowCallback, (LPARAM)processId);
}The Explorer process and desktop shell cleanup and exit cleanly. If there are multiple explorer.exe processes then you have to send these message to both processes. This code only sends the message to the shell window as an example showing it cleanup and exit successfully. These messages and functions are documented and supported by Microsoft: |
No description provided.