Skip to content

Commit

Permalink
Allow running as admin in Wine
Browse files Browse the repository at this point in the history
The admin privileges check introduced in #254 prevents working at all in
Wine, which always reports admin privileges. Since there's no danger of
causing permissions problems in that case, allow it as a special case.

Hopefully closes #1720.
  • Loading branch information
foresto committed Nov 24, 2023
1 parent 5e44cb4 commit c368b52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Setup/UpdateRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ 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) {
return S_FALSE;
}
if (!GetProcAddress(hntdll, L"wine_get_version")) {
return S_FALSE;
}
return S_OK;
}

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 c368b52

Please sign in to comment.