Skip to content

Commit

Permalink
Merge branch 'pr/1868' into develop
Browse files Browse the repository at this point in the history
* pr/1868:
  Allow running as admin in Wine
  • Loading branch information
anaisbetts committed Nov 24, 2023
2 parents 5e44cb4 + 1bc2a6a commit aaec357
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Setup/UpdateRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ void CUpdateRunner::DisplayErrorMessage(CString& errorMessage, wchar_t* logFile)
}
}

HRESULT CUpdateRunner::AreWeInWine()
{
// NB: Behaving differently in Wine is *usually* discouraged
// https://wiki.winehq.org/Developer_FAQ#How_can_I_detect_Wine.3F
HMODULE hntdll = GetModuleHandle(L"ntdll.dll");
if (!hntdll) {
// NB: This can never fail but we'll be pedantic
return E_FAIL;
}

return GetProcAddress(hntdll, "wine_get_version") != NULL ? S_OK : S_FALSE;
}

HRESULT CUpdateRunner::AreWeUACElevated()
{
HANDLE hProcess = GetCurrentProcess();
Expand Down
1 change: 1 addition & 0 deletions src/Setup/UpdateRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CUpdateRunner

public:
static void DisplayErrorMessage(CString& errorMessage, wchar_t* logFile);
static HRESULT AreWeInWine();
static HRESULT AreWeUACElevated();
static HRESULT ShellExecuteFromExplorer(LPWSTR pszFile, LPWSTR pszParameters);
static bool DirectoryExists(wchar_t* szPath);
Expand Down
3 changes: 2 additions & 1 deletion src/Setup/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

// If we're UAC-elevated, we shouldn't be because it will give us permissions
// problems later. Just silently rerun ourselves.
if (weAreUACElevated) {
// (Skip this check in Wine, which always reports admin privileges)
if (weAreUACElevated && CUpdateRunner::AreWeInWine() != S_OK) {
wchar_t buf[4096];
HMODULE hMod = GetModuleHandle(NULL);
GetModuleFileNameW(hMod, buf, 4096);
Expand Down

0 comments on commit aaec357

Please sign in to comment.