From 03cc65f491558382144c6defe3602e2d7471b2af Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 15 Dec 2021 04:48:24 +0200 Subject: [PATCH] Fixed #567 --- ExplorerPatcher/updates.c | 49 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/ExplorerPatcher/updates.c b/ExplorerPatcher/updates.c index df57b68..32643ed 100644 --- a/ExplorerPatcher/updates.c +++ b/ExplorerPatcher/updates.c @@ -314,7 +314,7 @@ BOOL IsUpdateAvailableHelper( printf( "[Updates] In order to install this update for the product \"" PRODUCT_NAME - "\", please allow the elevation request.\n" + "\", please allow the request.\n" ); #endif @@ -325,6 +325,47 @@ BOOL IsUpdateAvailableHelper( (*toast) = NULL; } + BOOL bHasErrored = FALSE; + BOOL bIsUACEnabled = FALSE; + DWORD(*CheckElevationEnabled)(BOOL*) = GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CheckElevationEnabled"); + if (CheckElevationEnabled) CheckElevationEnabled(&bIsUACEnabled); + DWORD dwData = FALSE, dwSize = sizeof(DWORD); + RegGetValueW( + HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", + L"ConsentPromptBehaviorAdmin", + RRF_RT_DWORD, + NULL, + &dwData, + &dwSize + ); + if (!bIsUACEnabled || !dwData) + { + WCHAR wszURL2[MAX_PATH]; + ZeroMemory(wszURL2, MAX_PATH * sizeof(WCHAR)); + MultiByteToWideChar( + CP_UTF8, + MB_PRECOMPOSED, + url, + -1, + wszURL2, + MAX_PATH + ); + + WCHAR wszMsg[500]; + swprintf_s(wszMsg, 500, L"Would you like to install an update for " _T(PRODUCT_NAME) L"?\n\nDownloaded from: \"%s\".\n", wszURL2); + if (MessageBoxW( + FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), + wszMsg, + _T(PRODUCT_NAME), + MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION + ) == IDNO) + { + bHasErrored = TRUE; + SetLastError(ERROR_CANCELLED); + } + } + SHELLEXECUTEINFO ShExecInfo = { 0 }; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; @@ -335,7 +376,7 @@ BOOL IsUpdateAvailableHelper( ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; - if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) + if (!bHasErrored && ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) { WaitForSingleObject(ShExecInfo.hProcess, INFINITE); DWORD dwExitCode = 0; @@ -361,7 +402,7 @@ BOOL IsUpdateAvailableHelper( if (dwError == ERROR_CANCELLED) { #ifdef UPDATES_VERBOSE_OUTPUT - printf("[Updates] Update failed because the elevation request was denied.\n"); + printf("[Updates] Update failed because the request was denied.\n"); #endif } else @@ -804,7 +845,7 @@ BOOL InstallUpdatesIfAvailable( L" \r\n" L" \r\n" L" \r\n" - L" \r\n" + L" \r\n" L" \r\n" L" \r\n" L" \r\n"