From e53398b4562381c4e656525f84cb3e4f09d0558b Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Wed, 8 Jun 2022 16:41:08 +0200 Subject: [PATCH] Fix win11 check --- .github/actions/spell-check/expect.txt | 1 + src/modules/powerrename/dll/dllmain.cpp | 54 ++++++++++++------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 7e37f9f67a..26ef02c455 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1535,6 +1535,7 @@ powerlauncher powerpreview powerrename POWERRENAMECONTEXTMENU +powerrenameinput POWERRENAMETEST powertoy powertoysinterop diff --git a/src/modules/powerrename/dll/dllmain.cpp b/src/modules/powerrename/dll/dllmain.cpp index cd4a711f2d..3f528d2851 100644 --- a/src/modules/powerrename/dll/dllmain.cpp +++ b/src/modules/powerrename/dll/dllmain.cpp @@ -10,47 +10,43 @@ #include #include "Generated Files/resource.h" #include -#include +#include #include #include #include #include -#include std::atomic g_dwModuleRefCount = 0; HINSTANCE g_hInst = 0; -#define STATUS_SUCCESS 0x00000000 -typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); - namespace { - RTL_OSVERSIONINFOW GetRealOSVersion() + BOOL IsWin11OrGreater() { - HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); - if (hMod) - { - 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; - } + OSVERSIONINFOEX osvi; + DWORDLONG dwlConditionMask = 0; + int op = VER_GREATER_EQUAL; - bool IsWindows11() - { - auto info = GetRealOSVersion(); - return info.dwMajorVersion >= 10 && info.dwBuildNumber >= 22000; - } + // Initialize the OSVERSIONINFOEX structure. + 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) { @@ -274,7 +270,7 @@ public: Logger::info(L"PowerRename enabled"); m_enabled = true; - if (IsWindows11()) + if (IsWin11OrGreater()) { std::wstring path = get_module_folderpath(g_hInst); std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";