Get Windows OS version as string

Y

Yoavo

Hi,
How can I retrieve the Windows OS version as string ?
I need to present this information in my application GUI.
I am familier with the functions that retrieve this information as enum, but
I do not want to parse it myself (and need to update the code every time a
new OS will be released).

In other words, I need the information that presented in "My Computer" ->
"Properties" (under "Windows Edition" section).

thanks,
Yoav.
 
P

Peter Duniho

Yoavo said:
Hi,
How can I retrieve the Windows OS version as string ?
I need to present this information in my application GUI.
I am familier with the functions that retrieve this information as enum,
but I do not want to parse it myself (and need to update the code every
time a new OS will be released). [...]

What functions are you familiar with? The .NET ones provide just what
I'd think you'd want, including a pre-formatted string. See the
System.Environment.OSVersion.VersionString property.

Pete
 
J

Jackie

Hi,
How can I retrieve the Windows OS version as string ?
I need to present this information in my application GUI.
I am familier with the functions that retrieve this information as enum,
but I do not want to parse it myself (and need to update the code every
time a new OS will be released).

In other words, I need the information that presented in "My Computer"
-> "Properties" (under "Windows Edition" section).

thanks,
Yoav.


Like Peter said, Environment.OSVersion should be the .NET method to get
version information. It will however not show the product name (such as
XP, Vista or Windows 7), but instead something similar to "Microsoft
Windows NT 6.1.7600.0". Your application will need to know the the
product names and check Platform and Version to identify which one it is.
http://msdn.microsoft.com/en-us/library/system.environment.osversion.aspx

You can also retrieve the product name with WMI:
Win32_OperatingSystem.Caption
http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx

"Short description of the object—a one-line string. The string includes
the operating system version. For example, "Microsoft Windows XP
Professional Version = 5.1.2500". This property can be localized."
 
F

Fred Mellender

How about :

OperatingSystem os = Environment.OSVersion;
string foo = os.ToString();
to get: foo = "Microsoft Windows NT 6.1.7600.0"
 
A

Arne Vajhøj

Hi,
How can I retrieve the Windows OS version as string ?
I need to present this information in my application GUI.
I am familier with the functions that retrieve this information as enum,
but I do not want to parse it myself (and need to update the code every
time a new OS will be released).

In other words, I need the information that presented in "My Computer"
-> "Properties" (under "Windows Edition" section).

using System;
using System.Management;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Environment.OSVersion);
ObjectQuery wmios = new WqlObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher oss = new
ManagementObjectSearcher(wmios);
foreach (ManagementObject os in oss.Get())
{
Console.WriteLine(os["Caption"]);
}
}
}
}

should display something.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top