Boardy Boardy - 1 year ago 261
C# Question

Get OS Version / Friendly Name in C#

I am currently working on a C# project. I want to collect users statistics to better develop the software. I am using the

feature of C# but its only showing the OS name as something like Microsoft Windows NT ...

What I want to be able to retrieve is the actual known name of the OS like whether it is
Windows XP, Windows Vista or Windows 7
and etc.

Is this possible?

Thanks for any help you can offer.

Answer Source

Add a reference and using statements for System.Management, then:

public static string GetOSFriendlyName()
    string result = string.Empty;
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
    foreach (ManagementObject os in searcher.Get())
        result = os["Caption"].ToString();
    return result;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download