什么是一个WinForms应用程序,以确定到底是哪Windows操作系统正在运行的最佳途径? [英] What is the best way for a WinForms application to determine exactly which Windows operating system it is running on?

查看:91
本文介绍了什么是一个WinForms应用程序,以确定到底是哪Windows操作系统正在运行的最佳途径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,需要在此基础上正在运行的操作系统在特定的行为方式(具体壳有一定的安装程序)。

I have a WinForms application that needs to behave in specific ways (specifically shell to a certain installer) based on the operating system on which it is running.

我现在用的是System.OperatingSystem类,并结合PlatFormID,主要,次要和内部版本号这让你最那里的方式。

I am using the System.OperatingSystem class, and combining the PlatFormID, Major, Minor and Build numbers which gets you most of the way there.

不幸的是,OperatinSystem的性质在对象,不要让你的一些平台之间的区别恰恰。例如。 Vista和Windows Server 2008或Windows Vista 32位和Vista 64位。同样,XP 64位专业版似乎有相同的版本信息为Server 2003中。

Unfortunately, the properites of an OperatinSystem object, do not allow you to distinguish precisely between some platforms. E.g. Vista and Windows Server 2008, or Vista 32 bit and Vista 64 bit. Likewise, XP 64 bit Professional seems to have the same versioning info as Server 2003.

那么,这可能确定到底是哪Windows操作系统在运行时,从WinForms应用程序(使用C#)?

So is it possible to determine exactly which Windows operating system you are running on, from a WinForms App (using c#)?

推荐答案

32位和64位的区分最简单的方法就是通过环境变量 PROCESSOR_ARCHITECTURE

The easiest way to distinguish between 32bit and 64bit is through environmental variable PROCESSOR_ARCHITECTURE.

string value = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");

如果您运行在32位的Windows此代码,将不是86或为空。在64位的Windows我相信它会被设置为任何东西,但86。那种混乱,但到目前为止,它适用于所有版本的Windows,你可以执行.NET程序。

if you run this code on 32bit Windows, value will be either "x86" or empty. On 64bit Windows I assume it will be set to anything but "x86". Kind of messy but so far it works on all versions of Windows where you can execute .NET program.

您还可以使用更现代化的WMI查询有关实际操作的所有信息系统可以想像,但这只能在Windows 2000或更新工作。如果你可以忍受的,的勾选此博客张贴一些范例

You can also use more modern WMI to query practically all information about operating system you can imagine but this will only work on Windows 2000 or newer. If you can live with that, check this blog post for some examples.

这篇关于什么是一个WinForms应用程序,以确定到底是哪Windows操作系统正在运行的最佳途径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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