mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Fix win11 check
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -1535,6 +1535,7 @@ powerlauncher
|
|||||||
powerpreview
|
powerpreview
|
||||||
powerrename
|
powerrename
|
||||||
POWERRENAMECONTEXTMENU
|
POWERRENAMECONTEXTMENU
|
||||||
|
powerrenameinput
|
||||||
POWERRENAMETEST
|
POWERRENAMETEST
|
||||||
powertoy
|
powertoy
|
||||||
powertoysinterop
|
powertoysinterop
|
||||||
|
|||||||
@@ -10,47 +10,43 @@
|
|||||||
#include <common/utils/resources.h>
|
#include <common/utils/resources.h>
|
||||||
#include "Generated Files/resource.h"
|
#include "Generated Files/resource.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <versionhelpers.h>
|
#include <VersionHelpers.h>
|
||||||
#include <dll/PowerRenameConstants.h>
|
#include <dll/PowerRenameConstants.h>
|
||||||
#include <winrt/Windows.ApplicationModel.h>
|
#include <winrt/Windows.ApplicationModel.h>
|
||||||
#include <winrt/Windows.Foundation.h>
|
#include <winrt/Windows.Foundation.h>
|
||||||
#include <winrt/Windows.Management.Deployment.h>
|
#include <winrt/Windows.Management.Deployment.h>
|
||||||
#include <bcrypt.h>
|
|
||||||
|
|
||||||
std::atomic<DWORD> g_dwModuleRefCount = 0;
|
std::atomic<DWORD> g_dwModuleRefCount = 0;
|
||||||
HINSTANCE g_hInst = 0;
|
HINSTANCE g_hInst = 0;
|
||||||
|
|
||||||
#define STATUS_SUCCESS 0x00000000
|
|
||||||
typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
RTL_OSVERSIONINFOW GetRealOSVersion()
|
BOOL IsWin11OrGreater()
|
||||||
{
|
{
|
||||||
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
|
OSVERSIONINFOEX osvi;
|
||||||
if (hMod)
|
DWORDLONG dwlConditionMask = 0;
|
||||||
{
|
int op = VER_GREATER_EQUAL;
|
||||||
RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
|
|
||||||
if (fxPtr != nullptr)
|
|
||||||
{
|
|
||||||
RTL_OSVERSIONINFOW info = { 0 };
|
|
||||||
info.dwOSVersionInfoSize = sizeof(info);
|
|
||||||
if (STATUS_SUCCESS == fxPtr(&info))
|
|
||||||
{
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RTL_OSVERSIONINFOW info = { 0 };
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsWindows11()
|
// Initialize the OSVERSIONINFOEX structure.
|
||||||
{
|
|
||||||
auto info = GetRealOSVersion();
|
|
||||||
return info.dwMajorVersion >= 10 && info.dwBuildNumber >= 22000;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
||||||
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||||
|
osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_WINTHRESHOLD);
|
||||||
|
osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_WINTHRESHOLD);
|
||||||
|
// Windows 11 build number
|
||||||
|
osvi.dwBuildNumber = 22000;
|
||||||
|
|
||||||
|
// Initialize the condition mask.
|
||||||
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
|
||||||
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
|
||||||
|
VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, op);
|
||||||
|
|
||||||
|
// Perform the test.
|
||||||
|
return VerifyVersionInfo(
|
||||||
|
&osvi,
|
||||||
|
VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER,
|
||||||
|
dwlConditionMask);
|
||||||
|
}
|
||||||
|
|
||||||
bool RegisterSparsePackage(std::wstring externalLocation, std::wstring sparsePkgPath)
|
bool RegisterSparsePackage(std::wstring externalLocation, std::wstring sparsePkgPath)
|
||||||
{
|
{
|
||||||
@@ -274,7 +270,7 @@ public:
|
|||||||
Logger::info(L"PowerRename enabled");
|
Logger::info(L"PowerRename enabled");
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
|
|
||||||
if (IsWindows11())
|
if (IsWin11OrGreater())
|
||||||
{
|
{
|
||||||
std::wstring path = get_module_folderpath(g_hInst);
|
std::wstring path = get_module_folderpath(g_hInst);
|
||||||
std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";
|
std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";
|
||||||
|
|||||||
Reference in New Issue
Block a user