How Do I detect an OS version?
In Win32 SDK, we have an API GetVersionEx that returns the information in
OSVERSIONINFO structure. And then we can look at the values of various members
of structures to decide what version of operating system we are running on.
To accomplish the same
task, .NET SDK provides a class named Environment. In this class there is a
static method named OSVersion that returns OperatingSystem object. This object
can be used to get the value of operating system version.
I Interpret OperatingSystem Object
class has three properties that contain all the information that you will need
to get value of operating system version.
- Platform: This property returns a PlatformID value. This enum has three possible values.
- Win32NT Operating system is Windows NT
- Win32Windows Operating system is Windows 95 or later
- Win32S Operating system is Win32s running on a 16-bit version of Windows.
CSD: This property indicates Corrected Service Diskette number of the operating system or in other words this is a string representing the service pack installed for the operating system.
- Version: This property returns a Version class object. This class is nothing but the standard version class used for indicating any assembly's version. .NET defines a version value in the format Major.Minor.Revision.Build. The Version class has four properties that completely define the version of operating system or an assembly.
- Major - Major Version Number
- Minor - Minor Version Number
- Revision - Revision Number
- Build - Build Number
I would suggest you
read documentation to get in depth details about what these values stand for and
how .NET uses these values to load the right version of an assembly for any
What All These Values Mean
You can combine the values returned by the above three values to get the exact
version of OS (Windows) running on the system. Since there are no details
available in .NET SDK, I assume the meaning of all the values remain the same as
Win32 SDK. Following is the table I used to extract the value of Operating
|PlatformID||Major Version||Minor Version||Operating System|
|Win32Windows||>= 4||> 0 && < 90||Win98|
|Win32Windows||>= 4||> 0 && >= 90||WinMe|
|Win32NT ||5||> 0||WinXP|
small sample from the class that shows the use of Environment class in System
Private os As OperatingSystem
' Get the version
Private vs As Version
' Get the service pack