Mic*_*ern 18 c# windows asp.net
使用System.Environment.OSVersion命名空间 确定托管ASP.NET应用程序的Microsoft OS的最佳方法是什么
我需要一个Windows XP,Windows Server 2003和Windows Vista的示例
这是我试图使用伪代码完成的
switch(/* Condition for determining OS */)
{
case "WindowsXP":
//Do Windows XP stuff
break;
case "Windows Server 2003":
//Do Windows Server 2003 stuff
break;
case "Windows Vista":
//Do Windows Vista stuff
break;
}
Run Code Online (Sandbox Code Playgroud)
Mic*_*ael 18
以下应该有效.但你为什么关心?仅用于日志记录中的信息目的,还是在寻找目标平台上存在的实际功能?
if (Environment.OSVersion.Version.Major == 5)
{
if (Environment.OSVersion.Version.Minor == 1)
{
// XP
}
else if (Environment.OSVersion.Version.Minor == 2)
{
// Server 2003. XP 64-bit will also fall in here.
}
}
else if (Environment.OSVersion.Version.Major >= 6)
{
// Vista on up
}
Run Code Online (Sandbox Code Playgroud)
Red*_*ter 10
不完整的列表,但从http://support.microsoft.com/kb/304283得到这个:
+--------------------------------------------------------------+ | |Windows|Windows|Windows|Windows NT|Windows|Windows| | | 95 | 98 | Me | 4.0 | 2000 | XP | +--------------------------------------------------------------+ |PlatformID | 1 | 1 | 1 | 2 | 2 | 2 | +--------------------------------------------------------------+ |Major | | | | | | | | version | 4 | 4 | 4 | 4 | 5 | 5 | +--------------------------------------------------------------+ |Minor | | | | | | | | version | 0 | 10 | 90 | 0 | 0 | 1 | +--------------------------------------------------------------+
编辑:注意,如果应用程序在兼容模式下运行,则System.Environment.OSVersion返回的信息可能不可靠.
Edit2:我建议你只需在你的应用程序中使它成为一个可配置的值 - 这样你的代码就不需要在新的操作系统出来时重新编译,例如Windows 7.
| 归档时间: |
|
| 查看次数: |
24354 次 |
| 最近记录: |