欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#获取系统版本信息方法

程序员文章站 2023-11-21 11:11:46
直接贴代码: 复制代码 代码如下: public class osinfomation { public static string osbit() { try { con...
直接贴代码:
复制代码 代码如下:

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();
}