private static bool IsWindows10BuildOrGreaterWin32(int build) { var osVer = new NtDll.OsVersionInfoEXW { DwMajorVersion = 10, DwMinorVersion = 0, DwBuildNumber = (uint)build }; const NtDll.TypeMask mask = NtDll.TypeMask.VerMajorVersion | NtDll.TypeMask.VerMinorVersion | NtDll.TypeMask.VerBuildNumber; ulong cond = NtDll.VerSetConditionMask(0, NtDll.TypeMask.VerMajorVersion, NtDll.Condition.VerGreaterEqual); cond = NtDll.VerSetConditionMask(cond, NtDll.TypeMask.VerMinorVersion, NtDll.Condition.VerGreaterEqual); cond = NtDll.VerSetConditionMask(cond, NtDll.TypeMask.VerBuildNumber, NtDll.Condition.VerGreaterEqual); // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the // latter lies unless the user knew to embed a non-default manifest // announcing support for Windows 10 via supportedOS GUID return(NtDll.RtlVerifyVersionInfo(ref osVer, mask, cond) == 0); }
/// <summary> /// Returns whether the windows version running on is at least the specified one. /// </summary> private static unsafe bool IsWindowsVersionOrGreaterWin32(int major, int minor, int sp) { var osVer = new NtDll.OsVersionInfoEXW { DwMajorVersion = (uint)major, DwMinorVersion = (uint)minor, DwBuildNumber = 0, DwPlatformId = 0, WServicePackMajor = (ushort)sp }; osVer.DwOSVersionInfoSize = (uint)Marshal.SizeOf(osVer); osVer.SzCsdVersion[0] = (char)0; const NtDll.TypeMask mask = NtDll.TypeMask.VerMajorVersion | NtDll.TypeMask.VerMinorVersion | NtDll.TypeMask.VerServicePackMajor; ulong cond = NtDll.VerSetConditionMask(0, NtDll.TypeMask.VerMajorVersion, NtDll.Condition.VerGreaterEqual); cond = NtDll.VerSetConditionMask(cond, NtDll.TypeMask.VerMinorVersion, NtDll.Condition.VerGreaterEqual); cond = NtDll.VerSetConditionMask(cond, NtDll.TypeMask.VerServicePackMajor, NtDll.Condition.VerGreaterEqual); // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the // latter lies unless the user knew to embed a non-default manifest // announcing support for Windows 10 via supportedOS GUID return(NtDll.RtlVerifyVersionInfo(ref osVer, mask, cond) == 0); }