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#)?
The easiest way to distinguish between 32bit and 64bit is through environmental variable
PROCESSOR_ARCHITECTURE.if you run this code on 32bit Windows,
valuewill 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.