mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
Merge Master Latest: 4/15/20
This commit is contained in:
@@ -364,27 +364,31 @@ WindowState get_window_state(HWND hwnd)
|
||||
return RESTORED;
|
||||
}
|
||||
|
||||
bool is_process_elevated()
|
||||
bool is_process_elevated(const bool use_cached_value)
|
||||
{
|
||||
HANDLE token = nullptr;
|
||||
bool elevated = false;
|
||||
auto detection_func = []() {
|
||||
HANDLE token = nullptr;
|
||||
bool elevated = false;
|
||||
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
|
||||
{
|
||||
TOKEN_ELEVATION elevation;
|
||||
DWORD size;
|
||||
if (GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &size))
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
|
||||
{
|
||||
elevated = (elevation.TokenIsElevated != 0);
|
||||
TOKEN_ELEVATION elevation;
|
||||
DWORD size;
|
||||
if (GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &size))
|
||||
{
|
||||
elevated = (elevation.TokenIsElevated != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token)
|
||||
{
|
||||
CloseHandle(token);
|
||||
}
|
||||
if (token)
|
||||
{
|
||||
CloseHandle(token);
|
||||
}
|
||||
|
||||
return elevated;
|
||||
return elevated;
|
||||
};
|
||||
static const bool cached_value = detection_func();
|
||||
return use_cached_value ? cached_value : detection_func();
|
||||
}
|
||||
|
||||
bool drop_elevated_privileges()
|
||||
|
||||
@@ -61,7 +61,7 @@ enum WindowState
|
||||
WindowState get_window_state(HWND hwnd);
|
||||
|
||||
// Returns true if the current process is running with elevated privileges
|
||||
bool is_process_elevated();
|
||||
bool is_process_elevated(const bool use_cached_value = true);
|
||||
|
||||
// Drops the elevated privilages if present
|
||||
bool drop_elevated_privileges();
|
||||
@@ -78,7 +78,7 @@ bool run_same_elevation(const std::wstring& file, const std::wstring& params);
|
||||
// Returns true if the current process is running from administrator account
|
||||
bool check_user_is_admin();
|
||||
|
||||
//Returns true when one or more strings from vector found in string
|
||||
// Returns true when one or more strings from vector found in string
|
||||
bool find_app_name_in_path(const std::wstring& where, const std::vector<std::wstring>& what);
|
||||
|
||||
// Get the executable path or module name for modern apps
|
||||
|
||||
@@ -38,6 +38,11 @@ std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool include_toolbar)
|
||||
return monitors;
|
||||
}
|
||||
|
||||
int MonitorInfo::GetMonitorsCount()
|
||||
{
|
||||
return GetMonitors(true).size();
|
||||
}
|
||||
|
||||
static BOOL CALLBACK get_primary_display_enum_cb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
|
||||
{
|
||||
MONITORINFOEX monitor_info;
|
||||
|
||||
@@ -32,6 +32,7 @@ struct MonitorInfo : ScreenSize
|
||||
|
||||
// Returns monitor rects ordered from left to right
|
||||
static std::vector<MonitorInfo> GetMonitors(bool include_toolbar);
|
||||
static int GetMonitorsCount();
|
||||
// Return primary display
|
||||
static MonitorInfo GetPrimaryMonitor();
|
||||
// Return monitor on which hwnd window is displayed
|
||||
|
||||
Reference in New Issue
Block a user