Archive

Posts Tagged ‘Version Detection’
help

C# Detect Windows OS Version – Part 1

June 22nd, 2009 Andrew 17 comments

Introduction

I recently needed to programmatically determine the Operating System my software is running on.  I was amazed at how difficult it was to find reliable, useful information on this subject.  There were bits and pieces here and there, but almost everyone assumed I had some pre-existing knowledge of the process in one manner or another.  Hopefully, this little series will save somebody some time in the future.

The thing that makes this so difficult is that there are almost as many different ways to detect the operating system as there are operating systems!  It’s an unbelievably frustrating experience trying to reinvent this wheel, so I’ll try to walk through it here.

Strategies

There are 4 basic strategies:

  1. Read and parse information from files in the Windows directory.  This is probably the most difficult and least rewarding method.  The files are different for each generation of OS and the format is not guaranteed in almost any case.
  2. Read information from the registry.  This method works a little better, but you still have varying locations for the information based on which OS you’re dealing with.
  3. Use Environment variables.  Nothing is more reliable.  However, it doesn’t give you the nitty-gritty detail you might want.  For example: There’s no way to detect XP Home vs. XP Professional.
  4. Use WMI to query for information about the OS.  This gives you everything you could possibly want all in one shot.  Unfortunately, it’s not supported in pre-NT versions of Windows.

I started with number 1.  After pulling most of my hair out and wanting to punch my keyboard, I moved on to number 2.  That was a dead end too.  I could have made it work, but I didn’t have the patience.  I gave number 3 a try and was very happy…  …until I decided that the specific version of 2000, XP, Vista, and 7 mattered to me.  So I finally ended up with a combination of 3 and 4.

For part 1 of this series, I’m going to focus on number 3, a.k.a. The Easy Waytm

Read more…

research
support
careers
jobs