Ejemplo n.º 1
0
        /// <summary>
        /// Indicates if the current OS version matches, or is greater than, the Windows 10 "Redstone 1" version.
        /// </summary>
        /// <returns>True if the current OS version matches, or is greater than, the Windows 10 "Redstone 1" version; otherwise, False.</returns>
        /// <remarks>
        /// This method is not intended to differentiate between specific Technical Preview builds of Windows Server 2016.
        ///
        /// RS1 will have a build number strictly greater than _TH2_BUILD_NUMBER.
        /// Once the precise build number for RS1 RTM is known, NativeConstants._RS1_BUILD_NUMBER
        /// should be defined, and the following implmentation should be updated to something like this:
        ///
        ///     return IsWindowsVersionOrGreater(
        ///             Util.HIBYTE(NativeConstants._WIN32_WINNT_WIN10),
        ///             Util.LOBYTE(NativeConstants._WIN32_WINNT_WIN10),
        ///             0,
        ///             NativeConstants._RS1_BUILD_NUMBER);
        ///
        /// In addition to updating the following implementation, a new method - IsWindows10RS2OrGreater -
        /// should be added along the lines of the implementation below.
        /// </remarks>
        public static bool IsWindows10RS1OrGreater()
        {
            var osvi = new NativeTypes.OSVERSIONINFOEX();

            osvi.dwMajorVersion = Util.HIBYTE(Win32WinNTConstants._WIN32_WINNT_WIN10);
            osvi.dwMinorVersion = Util.LOBYTE(Win32WinNTConstants._WIN32_WINNT_WIN10);
            osvi.dwBuildNumber  = Win10BuildNumbers._TH2_BUILD_NUMBER;


            ulong dwlConditionMask = 0;

            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_MAJORVERSION,
                ConditionMasks.VER_GREATER_EQUAL);

            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_MINORVERSION,
                ConditionMasks.VER_GREATER_EQUAL);

            // Build number should be strictly greater than than of TH2 - use VER_GREATER
            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_BUILDNUMBER,
                ConditionMasks.VER_GREATER);

            uint dwFlags =
                TypeBitMasks.VER_MAJORVERSION |
                TypeBitMasks.VER_MINORVERSION |
                TypeBitMasks.VER_BUILDNUMBER;

            return
                (NativeMethods.VerifyVersionInfo(osvi, dwFlags, dwlConditionMask));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Indicates if the current OS version matches, or is greater than, the OS version
        /// specified through <paramref name="wMajorVersion"/>, <paramref name="wMinorVersion"/>,
        /// <paramref name="wServicePackMajor"/> and <paramref name="wBuildNumber"/>.
        /// </summary>
        /// <param name="wMajorVersion">Major version</param>
        /// <param name="wMinorVersion">Minor version</param>
        /// <param name="wServicePackMajor">Service Pack's major version number</param>
        /// <param name="wBuildNumber">Build number of the OS</param>
        /// <returns>True if the current OS version matches, or is greater than, the OS version
        /// specified by the parameters, otherwise, False.</returns>
        private static bool IsWindowsVersionOrGreater(
            uint wMajorVersion,
            uint wMinorVersion,
            ushort wServicePackMajor,
            uint wBuildNumber = 0)
        {
            var osvi = new NativeTypes.OSVERSIONINFOEX();

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



            ulong dwlConditionMask = 0;

            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_MAJORVERSION,
                ConditionMasks.VER_GREATER_EQUAL);
            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_MINORVERSION,
                ConditionMasks.VER_GREATER_EQUAL);

            uint dwFlags =
                TypeBitMasks.VER_MAJORVERSION |
                TypeBitMasks.VER_MINORVERSION;


            if (wServicePackMajor > 0)
            {
                osvi.wServicePackMajor = wServicePackMajor;
                NativeMethods.VER_SET_CONDITION(
                    ref dwlConditionMask,
                    TypeBitMasks.VER_SERVICEPACKMAJOR,
                    ConditionMasks.VER_GREATER_EQUAL);
                dwFlags |= TypeBitMasks.VER_SERVICEPACKMAJOR;
            }

            if (wBuildNumber > 0)
            {
                osvi.dwBuildNumber = wBuildNumber;
                NativeMethods.VER_SET_CONDITION(
                    ref dwlConditionMask,
                    TypeBitMasks.VER_BUILDNUMBER,
                    ConditionMasks.VER_GREATER_EQUAL);
                dwFlags |= TypeBitMasks.VER_BUILDNUMBER;
            }

            return(NativeMethods.VerifyVersionInfo(osvi, dwFlags, dwlConditionMask));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Indicates if the current OS is a Windows Server release. Applications that need to distinguish
        /// between server and client versions of Windows should call this function.
        /// </summary>
        /// <returns>True if the current OS is a Windows Server version; otherwise, False.</returns>
        public static bool IsWindowsServer()
        {
            var   osvi             = new NativeTypes.OSVERSIONINFOEX();
            ulong dwlConditionMask = 0;

            osvi.wProductType = ProductTypes.VER_NT_WORKSTATION;
            NativeMethods.VER_SET_CONDITION(
                ref dwlConditionMask,
                TypeBitMasks.VER_PRODUCT_TYPE,
                ConditionMasks.VER_EQUAL);

            return
                (!NativeMethods.VerifyVersionInfo(osvi, TypeBitMasks.VER_PRODUCT_TYPE, dwlConditionMask));
        }
Ejemplo n.º 4
0
        internal static bool VerifyVersionInfo(NativeTypes.OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask)
        {
            var result = RtlVerifyVersionInfo(lpVersionInfo, dwTypeMask, dwlConditionMask);

            if (result == NtStatus.STATUS_INVALID_PARAMETER)
            {
                throw new ArgumentException(string.Empty, string.Empty);
            }

            System.Diagnostics.Debug.Assert(
                (result == NtStatus.STATUS_SUCCESS) ||
                (result == NtStatus.STATUS_REVISION_MISMATCH));

            return(result == NtStatus.STATUS_SUCCESS);
        }
Ejemplo n.º 5
0
 private static extern uint RtlVerifyVersionInfo([In] NativeTypes.OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask);