深入C#判断操作系统类型的总结详解(转载)

 

Windows操作系统的版本号一览

 

操作系统 PlatformID 主版本号 副版本号
 Windows95 1 4 0
 Windows98 1 4 10
 WindowsMe 1 4 90
 WindowsNT3.5 2 3 0
 WindowsNT4.0 2 4 0
 Windows2000 2 5 0
 WindowsXP 2 5 1
 Windows2003 2 5 2
 WindowsVista 2 6 0
 Windows7 2 6 1
 Windows8   

 

获取操作系统信息的相关类或属性

复制代码 代码如下:

//获取系统信息
System.OperatingSystem osInfo = System.Environment.OSVersion;
//获取操作系统ID
System.PlatformID platformID = osInfo.Platform;
//获取主版本号
int versionMajor = osInfo.Version.Major;
//获取副版本号
int versionMinor = osInfo.Version.Minor;


System.PlatformID枚举值及其含义

复制代码 代码如下:

Win32S  操作系统为 Win32s(Win32 子集)类型。
Win32s 是运行于 Windows 16 位版本上的层,它提供对 32 位应用程序的访问。
Win32Windows  操作系统为 Windows 95 或较新的版本。
Win32NT 操作系统为 Windows NT 或较新的版本。
WinCE   操作系统为 Windows CE。
Unix    操作系统为 Unix。
Xbox    开发平台为 Xbox 360。


示例

复制代码 代码如下:


//C#判断操作系统是否为Windows98
public static bool IsWindows98
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32Windows) && (Environment.OSVersion.Version.Minor == 10) && (Environment.OSVersion.Version.Revision.ToString() != "2222A");
    }
}
//C#判断操作系统是否为Windows98第二版
public static bool IsWindows98Second
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32Windows) && (Environment.OSVersion.Version.Minor == 10) && (Environment.OSVersion.Version.Revision.ToString() == "2222A");
    }
}
//C#判断操作系统是否为Windows2000
public static bool IsWindows2000
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor == 0);
    }
}
//C#判断操作系统是否为WindowsXP
public static bool IsWindowsXP {
    get {
        return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor == 1);
    }
}
//C#判断操作系统是否为Windows2003
public static bool IsWindows2003
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor == 2);
    }
}
//C#判断操作系统是否为WindowsVista
public static bool IsWindowsVista
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major == 6) && (Environment.OSVersion.Version.Minor == 0);
    }
}
//C#判断操作系统是否为Windows7
public static bool IsWindows7
{
    get
    {
        return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major == 6) && (Environment.OSVersion.Version.Minor == 1);
    }
}
//C#判断操作系统是否为Unix
public static bool IsUnix
{
    get
    {
        return Environment.OSVersion.Platform == PlatformID.Unix;
    }
}

转载于:https://www.cnblogs.com/candyzhmm/p/5704677.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值