确定使用Environment.OSVersion OS [英] Determine OS using Environment.OSVersion

查看:1424
本文介绍了确定使用Environment.OSVersion OS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的,以确定托管使用 System.Environment.OSVersion 命名空间的ASP.NET应用程序的微软操作系统

我需要为Windows XP为例,在Windows Server 2003和Windows Vista

下面就是我尝试使用完成伪code

 开关(/ *条件确定OS * /)
{
    案WindowsXP的:
        //完成Windows XP中的东西
        打破;
    情况下的Windows Server 2003:
        //完成Windows Server 2003中的东西
        打破;
    案的Windows Vista:
        //完成Windows Vista中的东西
        打破;
}


解决方案

下面应该工作。但是,为什么你在乎吗?仅仅是提供信息为目的的记录或者是你在寻找实际能力的目标平台?

这是present

 如果(Environment.OSVersion.Version.Major == 5)
{
    如果(Environment.OSVersion.Version.Minor == 1)
    {
             // XP
    }
    否则如果(Environment.OSVersion.Version.Minor == 2)
    {
             // Server 2003的XP 64位也将落在这里。
    }
}
否则如果(Environment.OSVersion.Version.Major> = 6)
{
        // Vista的最多
}

What is the best to determine the Microsoft OS that is hosting your ASP.NET application using the System.Environment.OSVersion namespace

I need an example for Windows XP, Windows Server 2003 and Windows Vista

Here is what I am trying to accomplish using pseudocode

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;
}

解决方案

The following should work. But why do you care? Is just for informational purposes in logging or are you looking for actual capabilities being present on the target platform?

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
}

这篇关于确定使用Environment.OSVersion OS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆