如何测试操作系统版本是否大于Windows XP SP2 [英] How to test if OS version is greater than Windows XP SP2

查看:64
本文介绍了如何测试操作系统版本是否大于Windows XP SP2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在编写一段代码,以确保该代码在OS为WindowsXPSP2或更高版本的计算机上唯一执行.我已经获得了OS ex-5.1,5.2的OS版本,依此类推.

Hi there I am writing a piece of code where I want to make sure that the code is onle executed on the machine in which OS is WindowsXPSP2 or greater. I have got OS version of the OS ex- 5.1,5.2 and so on.

我只想知道如何确保操作系统为WindowsXPSP2或更高版本?我可以使用版本号> 5.1进行检查吗?

I just want to know how can I make sure that the OS is either WindowsXPSP2 or greater? Can I check it with version number > 5.1?

推荐答案

尝试一下:

Version versionXPSP2 = new Version(5,2);
if (Environment.OSVersion.Version >= versionXPSP2)
{
    // this is XP SP2 or higher
}

(未经测试)

上面的代码实际上不起作用...这是另一个代码:

The code above actually doesn't work... here is another one :

Version version = Environment.OSVersion
if (version.Major > 5 || (version.Major == 5 && version.Minor >= 1 && version.ServicePack >= "Service Pack 2"))
{
    // this is XP SP2 or higher
}

这篇关于如何测试操作系统版本是否大于Windows XP SP2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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