Browse Source

Improved Explorer restart

pull/886/head
Valentin Radu 4 years ago
parent
commit
28de475e51
  1. 53
      ExplorerPatcher/GUI.c
  2. 64
      ep_setup/ep_setup.c

53
ExplorerPatcher/GUI.c

@ -771,33 +771,38 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
if (p) *p = 0; if (p) *p = 0;
if (!strncmp(line + 1, "restart", 7)) if (!strncmp(line + 1, "restart", 7))
{ {
if (FindWindowW(L"Shell_TrayWnd", NULL)) HWND hShellTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
if (hShellTrayWnd)
{ {
HANDLE hExplorerRestartThread = CreateThread(NULL, 0, BeginExplorerRestart, NULL, 0, NULL);
if (hExplorerRestartThread)
{
WaitForSingleObject(hExplorerRestartThread, 2000);
CloseHandle(hExplorerRestartThread);
hExplorerRestartThread = NULL;
}
else
{
BeginExplorerRestart();
}
Sleep(100);
//ZZRestartExplorer(0, 0, 0, 0);
WCHAR wszPath[MAX_PATH]; WCHAR wszPath[MAX_PATH];
ZeroMemory(wszPath, MAX_PATH * sizeof(WCHAR)); ZeroMemory(wszPath, MAX_PATH * sizeof(WCHAR));
GetSystemDirectoryW(wszPath, MAX_PATH); INT64 res = -1;
wcscat_s(wszPath, MAX_PATH, L"\\taskkill.exe"); if (!SendMessageTimeoutW(hShellTrayWnd, 1460, 0, 0, SMTO_ABORTIFHUNG, 2000, &res) && res)
ShellExecuteW( {
NULL, HANDLE hExplorerRestartThread = CreateThread(NULL, 0, BeginExplorerRestart, NULL, 0, NULL);
L"open", if (hExplorerRestartThread)
wszPath, {
L"/f /im explorer.exe", WaitForSingleObject(hExplorerRestartThread, 2000);
NULL, CloseHandle(hExplorerRestartThread);
SW_SHOWMINIMIZED hExplorerRestartThread = NULL;
); }
else
{
BeginExplorerRestart();
}
Sleep(100);
//ZZRestartExplorer(0, 0, 0, 0);
GetSystemDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\taskkill.exe");
ShellExecuteW(
NULL,
L"open",
wszPath,
L"/f /im explorer.exe",
NULL,
SW_SHOWMINIMIZED
);
}
GetWindowsDirectoryW(wszPath, MAX_PATH); GetWindowsDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\explorer.exe"); wcscat_s(wszPath, MAX_PATH, L"\\explorer.exe");
Sleep(1000); Sleep(1000);

64
ep_setup/ep_setup.c

@ -438,36 +438,44 @@ int WINAPI wWinMain(
CoUninitialize(); CoUninitialize();
} }
HANDLE hExplorerRestartThread = CreateThread(NULL, 0, BeginExplorerRestart, NULL, 0, NULL); HWND hShellTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
if (hExplorerRestartThread) if (hShellTrayWnd)
{ {
WaitForSingleObject(hExplorerRestartThread, 2000); INT res = -1;
CloseHandle(hExplorerRestartThread); if (!SendMessageTimeoutW(hShellTrayWnd, 1460, 0, 0, SMTO_ABORTIFHUNG, 2000, &res) && res)
hExplorerRestartThread = NULL; {
} HANDLE hExplorerRestartThread = CreateThread(NULL, 0, BeginExplorerRestart, NULL, 0, NULL);
else if (hExplorerRestartThread)
{ {
BeginExplorerRestart(); WaitForSingleObject(hExplorerRestartThread, 2000);
} CloseHandle(hExplorerRestartThread);
Sleep(100); hExplorerRestartThread = NULL;
}
else
{
BeginExplorerRestart();
}
Sleep(100);
GetSystemDirectoryW(wszPath, MAX_PATH); GetSystemDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\taskkill.exe"); wcscat_s(wszPath, MAX_PATH, L"\\taskkill.exe");
SHELLEXECUTEINFOW sei; SHELLEXECUTEINFOW sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFOW)); ZeroMemory(&sei, sizeof(SHELLEXECUTEINFOW));
sei.cbSize = sizeof(sei); sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_NOCLOSEPROCESS; sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = NULL; sei.hwnd = NULL;
sei.hInstApp = NULL; sei.hInstApp = NULL;
sei.lpVerb = NULL; sei.lpVerb = NULL;
sei.lpFile = wszPath; sei.lpFile = wszPath;
sei.lpParameters = L"/f /im explorer.exe"; sei.lpParameters = L"/f /im explorer.exe";
sei.hwnd = NULL; sei.hwnd = NULL;
sei.nShow = SW_SHOWMINIMIZED; sei.nShow = SW_SHOWMINIMIZED;
if (ShellExecuteExW(&sei) && sei.hProcess) if (ShellExecuteExW(&sei) && sei.hProcess)
{ {
WaitForSingleObject(sei.hProcess, INFINITE); WaitForSingleObject(sei.hProcess, INFINITE);
CloseHandle(sei.hProcess); CloseHandle(sei.hProcess);
}
}
} }
HWND hWnd = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL); HWND hWnd = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL);

Loading…
Cancel
Save