当前位置:编程学习 > C#/ASP.NET >>

C#获取系统版本信息

直接贴代码:
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(); 
               }  //www.heatpress123.net
               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(); 

 
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,