获得操作系统版本

        /// <summary>
        /// Description : Get Operating System Version
        /// </summary>
        /// <param name="sOsVersionName"></param>
        /// <param name="bRaiseError"></param>
        public static void GetOsVersion(ref  string sOsVersionName, bool bRaiseError = true)
        {
            //TODO PVM This is wrong for Windows XP 64 bit, I have code somewhere for that.  Also not catering for Windows 7
            sOsVersionName = string.Empty;

            try
            {
                OperatingSystem verinfo = Environment.OSVersion;
                switch (verinfo.Platform)
                {
                    case PlatformID.Win32NT:
                        switch (verinfo.Version.Major)
                        {
                            case 3:
                                sOsVersionName = "Windows NT 3.51";
                                break;
                            case 4:
                                sOsVersionName = "Windows NT 4.0";
                                break;
                            case 5:
                                switch (verinfo.Version.Minor)
                                {
                                    case 0:
                                        sOsVersionName = "Windows 2000";
                                        break;
                                    case 1:
                                        sOsVersionName = "Windows XP";
                                        break;
                                    case 2:
                                        sOsVersionName = "Windows 2003";
                                        break;
                                }
                                break;
                            case 6:
                                switch (verinfo.Version.Minor)
                                {
                                    case 0:
                                        // or Windows Server 2008, but system runs on client edition of windows generally, so just show Windows Vista
                                        sOsVersionName = "Windows Vista";
                                        break;
                                    case 1:
                                        // or Windows Server 2008 R2, but system runs on client edition of windows generally, so just show Windows 7
                                        sOsVersionName = "Windows 7";
                                        break;
                                    case 2:
                                        sOsVersionName = "Windows 8";
                                        break;
                                    case 3:
                                        sOsVersionName = "Windows 8.1";
                                        break;
                                    default:
                                        break;
                                }
                                break;
                        }
                        break;

                    case PlatformID.Win32Windows:
                        switch (verinfo.Version.Major)
                        {
                            case 4:
                                switch (verinfo.Version.Minor)
                                {
                                    case 0:
                                        sOsVersionName = "Windows 95";
                                        break;
                                    case 10:
                                        sOsVersionName = "Windows 98";
                                        break;
                                    case 90:
                                        sOsVersionName = "Windows Me";
                                        break;
                                }
                                break;
                        }
                        break;

                    case PlatformID.Win32S:
                        sOsVersionName = "Windows 32s";
                        break;
                }
            }
            catch (Exception)
            {
                if (bRaiseError)
                    throw ();
            }
        }
原文地址:https://www.cnblogs.com/beyondGodLike/p/3653814.html