VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之深入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;
    }
}

相关教程