您的位置:首页 > 编程语言 > C#

C# 判断操作系统类型

2009-02-03 11:01 375 查看
/// <summary>

/// Gets a value indicating if the process is running in 64 bit environment.

/// </summary>

public static unsafe bool IsRunningOn64Bit

{

get { return (sizeof(IntPtr) == sizeof(long)); }

}

/// <summary>

/// Gets a value indicating if the operating system is a Windows 2000 or a newer one.

/// </summary>

public static bool IsWindows2000OrNewer

{

get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 5); }

}

/// <summary>

/// Gets a value indicating if the operating system is a Windows XP or a newer one.

/// </summary>

public static bool IsWindowsXpOrNewer

{

get

{

return

(Environment.OSVersion.Platform == PlatformID.Win32NT) &&

(

(Environment.OSVersion.Version.Major >= 6) ||

(

(Environment.OSVersion.Version.Major == 5) &&

(Environment.OSVersion.Version.Minor >= 1)

)

);

}

}

/// <summary>

/// Gets a value indicating if the operating system is a Windows Vista or a newer one.

/// </summary>

public static bool IsWindowsVistaOrNewer

{

get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }

}

编译项目:“可编译不安全代码”属性设置为true

方法如下:项目属性对话框->配置属性->生成->允许不安全代码块 设为"true\"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: