C#获取系统版本信息方法
更新时间:2012年11月29日 12:01:23 作者:
今天做一个获取系统版本信息的实例,其获取方法很简单,需要的朋友可以参考下
直接贴代码:
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();
}
复制代码 代码如下:
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#连接SQL Sever数据库与数据查询实例之数据仓库详解
最近的工作遇到了连接查询,特在此记录,以免日后以往,下面这篇文章主要给大家介绍了关于C#连接SQL Sever数据库与数据查询实例之数据仓库的相关资料,文中通过图文介绍的非常详细,需要的朋友可以参考下2022-06-06BootStrap mvcpager分页样式(get请求,刷新页面)
这篇文章主要介绍了BootStrap mvcpager分页样式(get请求,刷新页面)的相关资料,通过引入相关文件,实现此功能,非常不错,具有参考借鉴价值,需要的朋友可以参考下2016-08-08
最新评论