C# 判断Windows版本及CPU位数
2010-11-17 10:14
246 查看
class
CheckWinVersion
{
int
getOSArchitecture()
{
string
pa = Environment.GetEnvironmentVariable(
"PROCESSOR_ARCHITECTURE"
);
return
((String.IsNullOrEmpty(pa) || String.Compare(pa, 0,
"x86"
, 0, 3,
true
) == 0) ? 32 : 64);
}
string
getOSInfo()
{
//Get Operating system information.
OperatingSystem os = Environment.OSVersion;
//Get version information about the os.
Version vs = os.Version;
//Variable to hold our return value
string
operatingSystem =
""
;
if
(os.Platform == PlatformID.Win32Windows)
{
//This is a pre-NT version of Windows
switch
(vs.Minor)
{
case
0:
operatingSystem = "95"
;
break
;
case
10:
if
(vs.Revision.ToString() ==
"2222A"
)
operatingSystem = "98SE"
;
else
operatingSystem = "98"
;
break
;
case
90:
operatingSystem = "Me"
;
break
;
default
:
break
;
}
}
else
if
(os.Platform == PlatformID.Win32NT)
{
switch
(vs.Major)
{
case
3:
operatingSystem = "NT 3.51"
;
break
;
case
4:
operatingSystem = "NT 4.0"
;
break
;
case
5:
if
(vs.Minor == 0)
operatingSystem = "2000"
;
else
operatingSystem = "XP"
;
break
;
case
6:
if
(vs.Minor == 0)
operatingSystem = "Vista"
;
else
operatingSystem = "7"
;
break
;
default
:
break
;
}
}
//Make sure we actually got something in our OS check
//We don't want to just return " Service Pack 2" or " 32-bit"
//That information is useless without the OS version.
if
(operatingSystem !=
""
)
{
//Got something. Let's prepend "Windows" and get more info.
operatingSystem = "Windows "
+ operatingSystem;
//See if there's a service pack installed.
if
(os.ServicePack !=
""
)
{
//Append it to the OS name. i.e. "Windows XP Service Pack 3"
operatingSystem += " "
+ os.ServicePack;
}
//Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit"
operatingSystem += " "
+ getOSArchitecture().ToString() +
"-bit"
;
}
//Return the information we've gathered.
return
operatingSystem;
}
}
CheckWinVersion
{
int
getOSArchitecture()
{
string
pa = Environment.GetEnvironmentVariable(
"PROCESSOR_ARCHITECTURE"
);
return
((String.IsNullOrEmpty(pa) || String.Compare(pa, 0,
"x86"
, 0, 3,
true
) == 0) ? 32 : 64);
}
string
getOSInfo()
{
//Get Operating system information.
OperatingSystem os = Environment.OSVersion;
//Get version information about the os.
Version vs = os.Version;
//Variable to hold our return value
string
operatingSystem =
""
;
if
(os.Platform == PlatformID.Win32Windows)
{
//This is a pre-NT version of Windows
switch
(vs.Minor)
{
case
0:
operatingSystem = "95"
;
break
;
case
10:
if
(vs.Revision.ToString() ==
"2222A"
)
operatingSystem = "98SE"
;
else
operatingSystem = "98"
;
break
;
case
90:
operatingSystem = "Me"
;
break
;
default
:
break
;
}
}
else
if
(os.Platform == PlatformID.Win32NT)
{
switch
(vs.Major)
{
case
3:
operatingSystem = "NT 3.51"
;
break
;
case
4:
operatingSystem = "NT 4.0"
;
break
;
case
5:
if
(vs.Minor == 0)
operatingSystem = "2000"
;
else
operatingSystem = "XP"
;
break
;
case
6:
if
(vs.Minor == 0)
operatingSystem = "Vista"
;
else
operatingSystem = "7"
;
break
;
default
:
break
;
}
}
//Make sure we actually got something in our OS check
//We don't want to just return " Service Pack 2" or " 32-bit"
//That information is useless without the OS version.
if
(operatingSystem !=
""
)
{
//Got something. Let's prepend "Windows" and get more info.
operatingSystem = "Windows "
+ operatingSystem;
//See if there's a service pack installed.
if
(os.ServicePack !=
""
)
{
//Append it to the OS name. i.e. "Windows XP Service Pack 3"
operatingSystem += " "
+ os.ServicePack;
}
//Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit"
operatingSystem += " "
+ getOSArchitecture().ToString() +
"-bit"
;
}
//Return the information we've gathered.
return
operatingSystem;
}
}
相关文章推荐
- C# 判断Windows版本及CPU位数
- C# System.Windows.Forms.WebBrowser中判断浏览器内核和版本
- Windows 系统版本判断
- 判断oracle版本位数的方法
- VS 中引入app.manifest(c#程序在win7及以上windows版本下以管理员权限运行方法)
- Windows中查看CPU位数
- C#对Windows服务操作(注册安装服务,卸载服务,启动停止服务,判断服务存在)
- C#判断字符串是否是满足指定位数的小数或整数
- C# 判断操作系统位数
- 如何使用 Visual C# .NET 检查 Windows 版本[转]
- C#完美实现多语言版本Windows应用程序
- 查看linux系统版本,内核,CPU,MEM,位数的相关命令(转)
- Windows下配置Caffe(CPU+GPU版本)
- win32程序判断windows系统(是否为win7或是更高版本)
- 判断windows 版本
- mxnet CPU版本Windows下简单安装(python接口安装)
- 使用C#检查Windows版本(转)
- 如何使用 Visual C# .NET 检查 Windows 版本[转]
- 使用C# 完美实现多语言版本Windows应用程序
- C#更改文件访问权限所有者(适用于各个Windows版本)