zoukankan      html  css  js  c++  java
  • 获得操作系统版本

            /// <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 ();
                }
            }
  • 相关阅读:
    函数模板
    可以接收数量不定的参数的函数
    Poco库的学习
    分割字符串,字符串去除空格
    初始化时添加click方法
    【Mybatis】传Map与传String
    jsp全局变量
    【oracle】Oracle中字符串连接的实现方法【转】
    斜杠(右斜杠)【/】 与 反斜杠(右斜杠)【】
    【Java】@ResponseBody 返回JsonObject
  • 原文地址:https://www.cnblogs.com/beyondGodLike/p/3653814.html
Copyright © 2011-2022 走看看