private static bool IsWindowsVersionOrGreater(uint majorVersion, uint minorVersion, ushort servicePackMajor) { var osvi = new NativeStructs.RTL_OSVERSIONINFOEXW(0); ulong conditionMask = Kernel32.VerSetConditionMask ( Kernel32.VerSetConditionMask ( Kernel32.VerSetConditionMask ( 0, NativeConstants.VER_MAJORVERSION, NativeConstants.VER_GREATER_EQUAL ), NativeConstants.VER_MINORVERSION, NativeConstants.VER_GREATER_EQUAL ), NativeConstants.VER_SERVICEPACKMAJOR, NativeConstants.VER_GREATER_EQUAL ); osvi.dwMajorVersion = majorVersion; osvi.dwMinorVersion = minorVersion; osvi.wServicePackMajor = servicePackMajor; return(NtDll.RtlVerifyVersionInfo(ref osvi, NativeConstants.VER_MAJORVERSION | NativeConstants.VER_MINORVERSION | NativeConstants.VER_SERVICEPACKMAJOR, conditionMask) == NativeConstants.STATUS_SUCCESS); }
public static bool IsWindowsServer() { var osvi = new NativeStructs.RTL_OSVERSIONINFOEXW(0); osvi.wProductType = NativeConstants.VER_NT_WORKSTATION; ulong conditionMask = Kernel32.VerSetConditionMask(0, NativeConstants.VER_PRODUCT_TYPE, NativeConstants.VER_EQUAL); var result = NtDll.RtlVerifyVersionInfo(ref osvi, NativeConstants.VER_PRODUCT_TYPE, conditionMask); bool clientOS = (result == NativeConstants.STATUS_SUCCESS); return(!clientOS); }
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); }