Boardy Boardy - 5 months ago 112
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.


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;