[Settings]Don't launch if explorer is running elevated (#18124)

This commit is contained in:
Andrey Nekrasov
2022-05-10 19:13:56 +03:00
committed by GitHub
parent 741457ffa5
commit c485da2816
4 changed files with 54 additions and 94 deletions

View File

@@ -83,7 +83,7 @@ namespace
inline bool GetDesktopAutomationObject(REFIID riid, void** ppv)
{
CComPtr<IShellView> spsv;
// Desktop may not be available on startup
auto attempts = 5;
for (auto i = 1; i <= attempts; i++)
@@ -492,4 +492,31 @@ inline bool check_user_is_admin()
freeMemory(pSID, pGroupInfo);
return false;
}
}
inline bool is_process_of_window_elevated(HWND window)
{
DWORD pid = 0;
GetWindowThreadProcessId(window, &pid);
if (!pid)
{
return false;
}
wil::unique_handle hProcess{ OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
pid) };
wil::unique_handle token;
if (OpenProcessToken(hProcess.get(), TOKEN_QUERY, &token))
{
TOKEN_ELEVATION elevation;
DWORD size;
if (GetTokenInformation(token.get(), TokenElevation, &elevation, sizeof(elevation), &size))
{
return elevation.TokenIsElevated != 0;
}
}
return false;
}