C#獲取系統(tǒng)版本信息
直接貼代碼:
public class OSInfoMation
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 "獲取錯(cuò)誤";
}
}
public static string GetOsVersion()
{
string osBitString = OSBit();
string osVersionString = Environment.OSVersion.ToString();
return string.Format(@"系統(tǒng):{0}。位:{1}", osVersionString, osBitString);
}
}
調(diào)用:
static void Main(string[] args)
{
Console.WriteLine(OSInfoMation.GetOsVersion());
Console.ReadLine();
}
結(jié)果:
系統(tǒng):Microsoft Windows NT 5.1.2600 Service Pack 3。位:32
原文;http://www.software8.co/wzjs/cpp/751.html
原文;http://www.software8.co/wzjs/cpp/751.html
posted on 2012-11-24 17:10 不聽話的 閱讀(1230) 評(píng)論(0) 編輯 收藏 引用