Skip to content
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

Allow running as admin in Wine #1868

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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