惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
D
Docker
云风的 BLOG
云风的 BLOG
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
GbyAI
GbyAI
T
Tailwind CSS Blog
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
C
Check Point Blog
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
N
Netflix TechBlog - Medium
B
Blog RSS Feed
腾讯CDC
aimingoo的专栏
aimingoo的专栏

博客园 - yufun

Windows GUI自动化测试技术的比较和展望 双屏(Daul Monitor)很爽 ChromePlus很好用,已经替代我的Firefox了 很久没来了,更新一下状态 小议云计算和Live Mesh、网络存储 [转载] 我的测试观点与经验 获取当前执行的函数(Testcase)名称 C#中三种截屏方式总结 搬家完成 你是否知道-你可把代码段拖拽到Toolbox里边 跟UI自动化测试有关的技术 转载:关于开发和测试 转载:再谈UI自动化测试 转载:一个UI自动化的小例子 转载:用一个小例子来说明手工测试,自动化测试,系统命令,编程语言,API的关系 各类搜索网站 在自动化测试中,如果控件不能识别,你会怎么做? 在C#中如何模拟鼠标键盘操作 - yufun - 博客园 在C#中调用API进行截屏
获取当前操作系统的版本 - yufun - 博客园
yufun · 2009-01-20 · via 博客园 - yufun

获取当前操作系统的版本

2009-01-20 14:46  yufun  阅读(628)  评论()    收藏  举报

OperatingSystem os = Environment.OSVersion;
switch (os.Platform)
{
    case PlatformID.Win32NT:
        switch (os.Version.Major)
        {
            case 3:
                return "Windows NT 3.51";
            case 4:
                return "Windows NT 4.0";
            case 5:
                switch (os.Version.Minor)
                {
                    case 0:
                        return "Windows 2000";
                    case 1:
                        return "Windows XP";
                    case 2:
                        return "Windows 2003";
                    default:
                        return "";
                }
            case 6:
                return "Windows Vista";
            default:
                return "";
        }
    case PlatformID.Win32S:
        return "";
    case PlatformID.Win32Windows:
        switch (os.Version.Minor)
        {
            case 0:
                return "Windows 95";
            case 10:
                if (os.Version.Revision.ToString() == "2222A")
                {
                    return "Windows 98 SE";
                }
                else
                {
                    return "Windows 98";
                }
            case 90:
                return "Windows Me";
            default:
                return "";
        }
    default:
        return "";
}

第二种比较简单的:

string rootKey = "HKEY_LOCAL_MACHINE";
string subKey = rootKey + @"\SOFTWARE\Microsoft\Windows NT\CurrentVersion";
object value = Registry.GetValue(subKey, "ProductName", null);
if (value != null)
{
    return value as string;
}
else
{
    return "";
}