コード例 #1
0
        public void TestOsVersionInfoEx()
        {
            var osVersionInfoEx = OsVersionInfoEx.Create();

            Assert.True(Kernel32Api.GetVersionEx(ref osVersionInfoEx));
            Assert.True(osVersionInfoEx.MajorVersion >= 6);
        }
コード例 #2
0
    static bool IsWindowsVersionOrGreater(
        uint majorVersion, uint minorVersion, ushort servicePackMajor)
    {
        OsVersionInfoEx osvi = new OsVersionInfoEx();

        osvi.OSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
        osvi.MajorVersion      = majorVersion;
        osvi.MinorVersion      = minorVersion;
        osvi.ServicePackMajor  = servicePackMajor;
        // These constants initialized with corresponding definitions in
        // winnt.h (part of Windows SDK)
        const uint VER_MINORVERSION     = 0x0000001;
        const uint VER_MAJORVERSION     = 0x0000002;
        const uint VER_SERVICEPACKMAJOR = 0x0000020;
        const byte VER_GREATER_EQUAL    = 3;
        ulong      versionOrGreaterMask = VerSetConditionMask(
            VerSetConditionMask(
                VerSetConditionMask(
                    0, VER_MAJORVERSION, VER_GREATER_EQUAL),
                VER_MINORVERSION, VER_GREATER_EQUAL),
            VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
        uint versionOrGreaterTypeMask = VER_MAJORVERSION |
                                        VER_MINORVERSION | VER_SERVICEPACKMAJOR;

        return(VerifyVersionInfo(ref osvi, versionOrGreaterTypeMask,
                                 versionOrGreaterMask));
    }
コード例 #3
0
        /// <summary>
        /// Indicates if the current OS version matches, or is greater than,
        /// the provided version information. This method is useful in
        /// confirming a version of Windows Server that doesn’t share a
        /// version number with a client release.
        /// </summary>
        /// <param name="majorVersion">The major OS version number.</param>
        /// <param name="minorVersion">The minor OS version number.</param>
        /// <param name="servicePackMajor">The major Service Pack version
        /// number.</param>
        /// <returns>True if the the running OS matches, or is greater
        /// than, the specified version information; otherwise, false.
        /// </returns>
        private static bool IsWindowsVersionOrGreater(uint majorVersion, uint minorVersion, ushort servicePackMajor)
        {
            var osvi = new OsVersionInfoEx();

            osvi.OSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
            osvi.MajorVersion      = majorVersion;
            osvi.MinorVersion      = minorVersion;
            osvi.ServicePackMajor  = servicePackMajor;

            // These constants initialized with corresponding definitions in
            // winnt.h (part of Windows SDK)
            const uint verMinor        = 0x0000001;
            const uint verMajor        = 0x0000002;
            const uint verServicePack  = 0x0000020;
            const byte verGreaterEqual = 3;

            if (!_versionOrGreaterMask.HasValue)
            {
                _versionOrGreaterMask = VerSetConditionMask(
                    VerSetConditionMask(
                        VerSetConditionMask(
                            0, verMajor, verGreaterEqual),
                        verMinor, verGreaterEqual),
                    verServicePack, verGreaterEqual);
            }

            if (!_versionOrGreaterTypeMask.HasValue)
            {
                _versionOrGreaterTypeMask = verMajor |
                                            verMinor | verServicePack;
            }

            return(VerifyVersionInfo(ref osvi, _versionOrGreaterTypeMask.Value,
                                     _versionOrGreaterMask.Value));
        }
コード例 #4
0
        private void Test_GetOsVersionInfoEx()
        {
            var osVersionInfoEx = OsVersionInfoEx.Create();

            Assert.True(Kernel32Api.GetVersionEx(ref osVersionInfoEx));
            //Assert.NotEmpty(osVersionInfoEx.ServicePackVersion);
        }
コード例 #5
0
 public static extern bool GetVersionEx([In, Out] OsVersionInfoEx osVer);
コード例 #6
0
        /// <summary>
        /// Indicates if the current OS version matches, or is greater than,
        /// the provided version information. This method is useful in
        /// confirming a version of Windows Server that doesn't share a
        /// version number with a client release.
        /// </summary>
        /// <param name="majorVersion">The major OS version number.</param>
        /// <param name="minorVersion">The minor OS version number.</param>
        /// <param name="servicePackMajor">The major Service Pack version
        /// number.</param>
        /// <returns>True if the the running OS matches, or is greater
        /// than, the specified version information; otherwise, false.
        /// </returns>
        internal static bool IsWindowsVersionOrGreater(
            uint majorVersion, uint minorVersion, ushort servicePackMajor)
        {
            OsVersionInfoEx osvi = new OsVersionInfoEx();
            osvi.OSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
            osvi.MajorVersion = majorVersion;
            osvi.MinorVersion = minorVersion;
            osvi.ServicePackMajor = servicePackMajor;

            // These constants initialized with corresponding definitions in
            // winnt.h (part of Windows SDK)
            const uint VER_MINORVERSION = 0x0000001;
            const uint VER_MAJORVERSION = 0x0000002;
            const uint VER_SERVICEPACKMAJOR = 0x0000020;
            const byte VER_GREATER_EQUAL = 3;

            if (!versionOrGreaterMask.HasValue)
            {
                versionOrGreaterMask = VerSetConditionMask(
                    VerSetConditionMask(
                        VerSetConditionMask(
                            0, VER_MAJORVERSION, VER_GREATER_EQUAL),
                        VER_MINORVERSION, VER_GREATER_EQUAL),
                    VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
            }

            if (!versionOrGreaterTypeMask.HasValue)
            {
                versionOrGreaterTypeMask = VER_MAJORVERSION |
                    VER_MINORVERSION | VER_SERVICEPACKMAJOR;
            }

            return VerifyVersionInfo(ref osvi, versionOrGreaterTypeMask.Value,
                versionOrGreaterMask.Value);
        }
コード例 #7
0
 private static extern bool VerifyVersionInfo(
     [In] ref OsVersionInfoEx lpVersionInfo,
     uint dwTypeMask, ulong dwlConditionMask);
コード例 #8
0
        /// <summary>
        /// Indicates if the current OS version matches, or is greater than,
        /// the provided version information. This method is useful in
        /// confirming a version of Windows Server that doesn't share a
        /// version number with a client release.
        /// </summary>
        /// <param name="majorVersion">The major OS version number.</param>
        /// <param name="minorVersion">The minor OS version number.</param>
        /// <param name="servicePackMajor">The major Service Pack version
        /// number.</param>
        /// <returns>True if the the running OS matches, or is greater
        /// than, the specified version information; otherwise, false.
        /// </returns>
        internal static bool IsWindowsVersionOrGreater(
            uint majorVersion, uint minorVersion, ushort servicePackMajor)
        {
            var osvi = new OsVersionInfoEx();
            osvi.OSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
            osvi.MajorVersion = majorVersion;
            osvi.MinorVersion = minorVersion;
            osvi.ServicePackMajor = servicePackMajor;

            // These constants initialized with corresponding definitions in
            // winnt.h (part of Windows SDK)
            const uint verMinorversion = 0x0000001;
            const uint verMajorversion = 0x0000002;
            const uint verServicepackmajor = 0x0000020;
            const byte verGreaterEqual = 3;

            if (!_versionOrGreaterMask.HasValue) {
                _versionOrGreaterMask = VerSetConditionMask(
                    VerSetConditionMask(
                        VerSetConditionMask(
                            0, verMajorversion, verGreaterEqual),
                        verMinorversion, verGreaterEqual),
                    verServicepackmajor, verGreaterEqual);
            }

            if (!_versionOrGreaterTypeMask.HasValue) {
                _versionOrGreaterTypeMask = verMajorversion |
                    verMinorversion | verServicepackmajor;
            }

            return VerifyVersionInfo(ref osvi, _versionOrGreaterTypeMask.Value,
                _versionOrGreaterMask.Value);
        }
コード例 #9
0
 internal static extern bool GetVersionEx(ref OsVersionInfoEx osVersionInfo);
コード例 #10
0
 public static extern bool GetVersionEx(ref OsVersionInfoEx osVersionInfo);
コード例 #11
0
 public static extern bool GetVersionEx([MarshalAs(UnmanagedType.Struct)] ref OsVersionInfoEx osvi);
コード例 #12
0
        private static string GetEditionMajorVersionSix(OsVersionInfoEx osVersion)
        {
            int ed;

            if (NativeMethods.GetProductInfo(osVersion.MajorVersion, osVersion.MinorVersion,
                                             osVersion.ServicePackMajor, osVersion.ServicePackMinor,
                                             out ed))
            {
                switch (ed)
                {
                case PRODUCT_BUSINESS:
                    return("Business");

                case PRODUCT_BUSINESS_N:
                    return("Business N");

                case PRODUCT_CLUSTER_SERVER:
                    return("HPC Edition");

                case PRODUCT_CLUSTER_SERVER_V:
                    return("HPC Edition without Hyper-V");

                case PRODUCT_DATACENTER_SERVER:
                    return("Datacenter Server");

                case PRODUCT_DATACENTER_SERVER_CORE:
                    return("Datacenter Server (core installation)");

                case PRODUCT_DATACENTER_SERVER_V:
                    return("Datacenter Server without Hyper-V");

                case PRODUCT_DATACENTER_SERVER_CORE_V:
                    return("Datacenter Server without Hyper-V (core installation)");

                case PRODUCT_EMBEDDED:
                    return("Embedded");

                case PRODUCT_ENTERPRISE:
                    return("Enterprise");

                case PRODUCT_ENTERPRISE_N:
                    return("Enterprise N");

                case PRODUCT_ENTERPRISE_E:
                    return("Enterprise E");

                case PRODUCT_ENTERPRISE_SERVER:
                    return("Enterprise Server");

                case PRODUCT_ENTERPRISE_SERVER_CORE:
                    return("Enterprise Server (core installation)");

                case PRODUCT_ENTERPRISE_SERVER_CORE_V:
                    return("Enterprise Server without Hyper-V (core installation)");

                case PRODUCT_ENTERPRISE_SERVER_IA64:
                    return("Enterprise Server for Itanium-based Systems");

                case PRODUCT_ENTERPRISE_SERVER_V:
                    return("Enterprise Server without Hyper-V");

                case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT:
                    return("Essential Business Server MGMT");

                case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL:
                    return("Essential Business Server ADDL");

                case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC:
                    return("Essential Business Server MGMTSVC");

                case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC:
                    return("Essential Business Server ADDLSVC");

                case PRODUCT_HOME_BASIC:
                    return("Home Basic");

                case PRODUCT_HOME_BASIC_N:
                    return("Home Basic N");

                case PRODUCT_HOME_BASIC_E:
                    return("Home Basic E");

                case PRODUCT_HOME_PREMIUM:
                    return("Home Premium");

                case PRODUCT_HOME_PREMIUM_N:
                    return("Home Premium N");

                case PRODUCT_HOME_PREMIUM_E:
                    return("Home Premium E");

                case PRODUCT_HOME_PREMIUM_SERVER:
                    return("Home Premium Server");

                case PRODUCT_HYPERV:
                    return("Microsoft Hyper-V Server");

                case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
                    return("Windows Essential Business Management Server");

                case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
                    return("Windows Essential Business Messaging Server");

                case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
                    return("Windows Essential Business Security Server");

                case PRODUCT_PROFESSIONAL:
                    return("Professional");

                case PRODUCT_PROFESSIONAL_N:
                    return("Professional N");

                case PRODUCT_PROFESSIONAL_E:
                    return("Professional E");

                case PRODUCT_SB_SOLUTION_SERVER:
                    return("SB Solution Server");

                case PRODUCT_SB_SOLUTION_SERVER_EM:
                    return("SB Solution Server EM");

                case PRODUCT_SERVER_FOR_SB_SOLUTIONS:
                    return("Server for SB Solutions");

                case PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM:
                    return("Server for SB Solutions EM");

                case PRODUCT_SERVER_FOR_SMALLBUSINESS:
                    return("Windows Essential Server Solutions");

                case PRODUCT_SERVER_FOR_SMALLBUSINESS_V:
                    return("Windows Essential Server Solutions without Hyper-V");

                case PRODUCT_SERVER_FOUNDATION:
                    return("Server Foundation");

                case PRODUCT_SMALLBUSINESS_SERVER:
                    return("Windows Small Business Server");

                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                    return("Windows Small Business Server Premium");

                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE:
                    return("Windows Small Business Server Premium (core installation)");

                case PRODUCT_SOLUTION_EMBEDDEDSERVER:
                    return("Solution Embedded Server");

                case PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE:
                    return("Solution Embedded Server (core installation)");

                case PRODUCT_STANDARD_SERVER:
                    return("Standard Server");

                case PRODUCT_STANDARD_SERVER_CORE:
                    return("Standard Server (core installation)");

                case PRODUCT_STANDARD_SERVER_SOLUTIONS:
                    return("Standard Server Solutions");

                case PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE:
                    return("Standard Server Solutions (core installation)");

                case PRODUCT_STANDARD_SERVER_CORE_V:
                    return("Standard Server without Hyper-V (core installation)");

                case PRODUCT_STANDARD_SERVER_V:
                    return("Standard Server without Hyper-V");

                case PRODUCT_STARTER:
                    return("Starter");

                case PRODUCT_STARTER_N:
                    return("Starter N");

                case PRODUCT_STARTER_E:
                    return("Starter E");

                case PRODUCT_STORAGE_ENTERPRISE_SERVER:
                    return("Enterprise Storage Server");

                case PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE:
                    return("Enterprise Storage Server (core installation)");

                case PRODUCT_STORAGE_EXPRESS_SERVER:
                    return("Express Storage Server");

                case PRODUCT_STORAGE_EXPRESS_SERVER_CORE:
                    return("Express Storage Server (core installation)");

                case PRODUCT_STORAGE_STANDARD_SERVER:
                    return("Standard Storage Server");

                case PRODUCT_STORAGE_STANDARD_SERVER_CORE:
                    return("Standard Storage Server (core installation)");

                case PRODUCT_STORAGE_WORKGROUP_SERVER:
                    return("Workgroup Storage Server");

                case PRODUCT_STORAGE_WORKGROUP_SERVER_CORE:
                    return("Workgroup Storage Server (core installation)");

                case PRODUCT_UNDEFINED:
                    return("Unknown product");

                case PRODUCT_ULTIMATE:
                    return("Ultimate");

                case PRODUCT_ULTIMATE_N:
                    return("Ultimate N");

                case PRODUCT_ULTIMATE_E:
                    return("Ultimate E");

                case PRODUCT_WEB_SERVER:
                    return("Web Server");

                case PRODUCT_WEB_SERVER_CORE:
                    return("Web Server (core installation)");
                }
            }

            return(string.Empty);
        }