C#获取系统版本信息

标签: c#stringmicrosoftnullservicewindows
3129人阅读 评论(0) 收藏 举报
分类:

 直接贴代码:

 public class OSInfoMation
    {
        public static string OSBit()
        {
            try
            {
                ConnectionOptions oConn = new ConnectionOptions();

                System.Management.ManagementScope managementScope = new System.Management.ManagementScope("\\\\localhost", oConn);

                System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery("select AddressWidth from Win32_Processor");

                ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(managementScope, objectQuery);

                ManagementObjectCollection moReturnCollection = null;

                string addressWidth = null;

                moReturnCollection = moSearcher.Get();
                
                foreach (ManagementObject oReturn in moReturnCollection)
                {
                    addressWidth = oReturn["AddressWidth"].ToString();
                }
                return addressWidth;
            }
            catch
            {
                return "获取错误";
            }

        }

        public static string GetOsVersion()
        {
            string osBitString = OSBit();

            string osVersionString = Environment.OSVersion.ToString();

            return string.Format(@"系统:{0}。位:{1}", osVersionString, osBitString);
        }
    }

调用:

        static void Main(string[] args)
        {
            Console.WriteLine(OSInfoMation.GetOsVersion());

            Console.ReadLine();
        }

结果:

系统:Microsoft Windows NT 5.1.2600 Service Pack 3。位:32

代码下载:http://download.csdn.net/detail/yysyangyangyangshan/4160546

10
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1810771次
    • 积分:23217
    • 等级:
    • 排名:第308名
    • 原创:396篇
    • 转载:19篇
    • 译文:0篇
    • 评论:493条
    博客专栏
    最新评论