To get Windows Product Name in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetWindowsProdutName()
{
	var name = (new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>().Select(x => x.GetPropertyValue("Caption"))).First();
	return name != null ? name.ToString() : "Unknown";
}

Sample VB.NET

Public Shared Function GetWindowsProdutName() As String
	Dim name = (New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").[Get]().OfType(Of ManagementObject)().[Select](Function(x) x.GetPropertyValue("Caption"))).First()
	Return If(name IsNot Nothing, name.ToString(), "Unknown")
End Function

Tipp: To use ManagementObjectSearcher you need to set a Reference to System.Management.

3 thought on “How to get Windows Product Name in C# and VB.NET”

Leave a Reply