Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way for a WinForms application to determine exactly which Windows operating system it is running on?

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.

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

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.

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

like image 625
Stuart Helwig Avatar asked Feb 11 '10 01:02

Stuart Helwig


People also ask

How do I find Windows Server version?

To find out which version of Windows your device is running, press the Windows logo key + R, type winver in the Open box, and then select OK. Here's how to learn more: Select Start > Settings > System > About .

What is difference between Winforms and Windows Forms?

Winforms and Windows Forms are the same thing. Winforms is the shortened name for Windows Forms.

What is WinForm application?

Windows Forms is a UI framework for building Windows desktop apps. It provides one of the most productive ways to create desktop apps based on the visual designer provided in Visual Studio. Functionality such as drag-and-drop placement of visual controls makes it easy to build desktop apps.


1 Answers

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

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

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.

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.

like image 97
lubos hasko Avatar answered Nov 02 '22 20:11

lubos hasko