mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Fix CurrentVirtualDesktop
fetching from registry (#11760)
* fix(#11125): fallback to canonical regkey session unaware * chore(#11125): use wil::unique_hkey instead of HKEY for fallback CurrentVirtualDesktop * refactor: extract new explorer current virtual desktop behavior into a separate method
This commit is contained in:
parent
f662c062d2
commit
5679d48073
@ -51,6 +51,23 @@ namespace VirtualDesktopUtils
|
|||||||
return SUCCEEDED(CLSIDFromString(virtualDesktopId.c_str(), desktopId));
|
return SUCCEEDED(CLSIDFromString(virtualDesktopId.c_str(), desktopId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NewGetCurrentDesktopId(GUID* desktopId)
|
||||||
|
{
|
||||||
|
wil::unique_hkey key{};
|
||||||
|
if (RegOpenKeyExW(HKEY_CURRENT_USER, NonLocalizable::RegKeyVirtualDesktops, 0, KEY_ALL_ACCESS, &key) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
GUID value{};
|
||||||
|
DWORD size = sizeof(GUID);
|
||||||
|
if (RegQueryValueExW(key.get(), NonLocalizable::RegCurrentVirtualDesktop, 0, nullptr, reinterpret_cast<BYTE*>(&value), &size) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
*desktopId = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool GetDesktopIdFromCurrentSession(GUID* desktopId)
|
bool GetDesktopIdFromCurrentSession(GUID* desktopId)
|
||||||
{
|
{
|
||||||
DWORD sessionId;
|
DWORD sessionId;
|
||||||
@ -76,11 +93,19 @@ namespace VirtualDesktopUtils
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetCurrentVirtualDesktopId(GUID* desktopId)
|
bool GetCurrentVirtualDesktopId(GUID* desktopId)
|
||||||
{
|
{
|
||||||
|
// On newer Windows builds, the current virtual desktop is persisted to
|
||||||
|
// a totally different reg key. Look there first.
|
||||||
|
if (NewGetCurrentDesktopId(desktopId))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Explorer persists current virtual desktop identifier to registry on a per session basis, but only
|
// Explorer persists current virtual desktop identifier to registry on a per session basis, but only
|
||||||
// after first virtual desktop switch happens. If the user hasn't switched virtual desktops in this
|
// after first virtual desktop switch happens. If the user hasn't switched virtual desktops in this
|
||||||
// session, value in registry will be empty.
|
// session, value in registry will be empty.
|
||||||
|
Loading…
Reference in New Issue
Block a user