tags:

views:

77

answers:

3
+2  Q: 

Retrieving OS name

Is there any way to get the OS name the user is currently using?

+3  A: 

You can use

System.Environment

class

Environment.OSVersion.ToString()

See Environment.OSVersion Property

Gets an OperatingSystem object that contains the current platform identifier and version number.

rahul
yeah!!! I'm aware of tat property. but how do i get the name of the OS..?? There is an API - win32_operatingsystem which gives me the OS name. But tat requires WMI service in runnin/stopped mode. Gettin error if the service is in paused state. So help me out wit a method to get the name of the OS if any.
Hanny
A: 

You can use the Environment.OSVersion property.

Version version = Environment.OSVersion;

To decode the version, refer to the wikipedia page of Microsoft Windows Timeline. For example, if the version is 6.1.7600, then it is either a Windows 7 or a Windows Server 2008 R2.

Note that there is no direct API to get the OS name, because a same version can refer to multiple public OS names.

Laurent Etiemble
A: 

You cannot retrieve the OS name directly. Instead use the Environment.OSVersion.ToString() property to interpret the version & display the OS Name.

This article has a sample that will help you. It covers Win95 to Win7.

All you need to do is write a function that will return the OS name as shown in the above article.

SoftwareGeek