Skip to content

About IsWindowsVersionOrGreaterFx function in OsInfoFx.cpp #3

@zyyujq

Description

@zyyujq

IsWindowsVersionOrGreaterFx (10,0) , on the exe execution file, there is an additional manifest file manifest:

manifest file:

< compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
< application>
< !-- Windows Vista -->
< supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
< !-- Windows 7 -->
< supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
< !-- Windows 8 -->
< supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
< !-- Windows 8.1 -->
< supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
< !-- Windows 10 -->
< supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
< /application>
< /compatibility>


So , can return TRUE on Windows 10 and 11.

If there is no manifest file, the exe execution file has an error on Windows 11.

if you build the CrystalDiskInfo.DLL file, even if the manifest file is attached, the shell program runs on Windows 11 and calls CrystalDiskInfo.DLL. Unfortunately, the program error.


I solved this problem temporarily with a simple method, even without the manifest file of the program.

In OsInfoFx.cpp:

#include "pch.h"
#include "stdafx.h"
#include "OsInfoFx.h"
#include "UtilityFx.h"

typedef BOOL (WINAPI* FuncGetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD);
typedef BOOL (WINAPI* FuncGetNativeSystemInfo)(LPSYSTEM_INFO);
typedef BOOL (WINAPI* FuncIsWow64Process)(HANDLE hProcess,PBOOL Wow64Process);
typedef LONG (WINAPI* FuncRtlGetVersion)(POSVERSIONINFOEXW osvi);

//---add
typedef LONG NTSTATUS, * PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)`

typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);

RTL_OSVERSIONINFOW GetRealOSVersion() {
	HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
	if (hMod) {
		RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
		if (fxPtr != nullptr) {
			RTL_OSVERSIONINFOW rovi = { 0 };
			rovi.dwOSVersionInfoSize = sizeof(rovi);
			if (STATUS_SUCCESS == fxPtr(&rovi)) {
				return rovi;
			}
		}
	}
	RTL_OSVERSIONINFOW rovi = { 0 };
	return rovi;
}
//---

BOOL IsWindowsVersionOrGreaterFx(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
{
	OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };
	DWORDLONG        const dwlConditionMask = VerSetConditionMask(
		                                                              VerSetConditionMask(
			                                                    VerSetConditionMask(
				                                           0, VER_MAJORVERSION, VER_GREATER_EQUAL),
			                                                VER_MINORVERSION, VER_GREATER_EQUAL),
		                                                  VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

	osvi.dwMajorVersion = wMajorVersion;
	osvi.dwMinorVersion = wMinorVersion;
	osvi.wServicePackMajor = wServicePackMajor;

//---add

	//osvi.dwBuildNumber= GetRealOSVersion().dwBuildNumber;
	//osvi.dwOSVersionInfoSize = GetRealOSVersion().dwOSVersionInfoSize;
	//osvi.dwPlatformId = GetRealOSVersion().dwPlatformId;


	DWORD wntMajorVersion= GetRealOSVersion().dwMajorVersion;//W11=10
	DWORD wntMinorVersion = GetRealOSVersion().dwMinorVersion;//W11=0
	DWORD wntBuildNumber = GetRealOSVersion().dwBuildNumber;//W11=22621
	DWORD wntPlatformId = GetRealOSVersion().dwPlatformId;//W11=2
	DWORD wntOSVersionInfoSize = GetRealOSVersion().dwOSVersionInfoSize;//W11=276
	WCHAR *wntszCSDVersion = GetRealOSVersion().szCSDVersion;//W11=0x012fd0e4

//---modify

	if ((wMajorVersion == wntMajorVersion) && (wntBuildNumber > 20000)) //Windows 11
	{
		return TRUE;
	}
	else
	{
		return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions