Get Os Version/Friendly Name in C#

Get OS Version / Friendly Name in C#

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();
break;
}
return result;
}

How to get the friendly OS Version Name?

You can use WMI to get the product name ("Microsoft® Windows Server® 2008 Enterprise "):

using System.Management;
var name = (from x in new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem").Get().Cast<ManagementObject>()
select x.GetPropertyValue("Caption")).FirstOrDefault();
return name != null ? name.ToString() : "Unknown";

How to get operating system name

System.OperatingSystem is a type, you couldn't asign it to a variable. What do you want to achieve? Name of running operating system? You could do it with:

Environment.OSVersion.ToString()

C# Get OS Name Windows 8.1

You could find that info in the registry of Windows. For example, if you have installed Windows 8.1 Pro Edition and execute this lines:

 using Microsoft.Win32;     
//...

var windowsName= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "ProductName","");
var version= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentVersion", "");
var build= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentBuild", "");

You will get Windows 8.1 Pro, 6.3 and 9600 respectively.

Also you could use the WMI to get the Windows name, check the answer in this post:

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();
break;
}
return result;
}

How can I get OS Name and Version details in C# on windows mobile 7?

you can try these links

http://msdn.microsoft.com/en-us/library/ff941122%28v=VS.92%29.aspx

http://msdn.microsoft.com/en-us/library/microsoft.phone.info.deviceextendedproperties%28v=VS.92%29.aspx

you can try this

   public MainPage()
{
InitializeComponent();
GetDeviceInfo();
}
public void GetDeviceInfo()
{
long ApplicationMemoryUsage = DeviceStatus.ApplicationCurrentMemoryUsage;
long PeakMemoryUsage = DeviceStatus.ApplicationPeakMemoryUsage;
string FirmwareVersion = DeviceStatus.DeviceFirmwareVersion;
string HardwareVersion = DeviceStatus.DeviceHardwareVersion;
string Manufacturer = DeviceStatus.DeviceManufacturer;
string DeviceName = DeviceStatus.DeviceName;
long TotalMemory = DeviceStatus.DeviceTotalMemory;
string OSVersion = Environment.OSVersion.Version.ToString(); ;
PowerSource powerSource = DeviceStatus.PowerSource;
AddToList("Memory Usage :" + ApplicationMemoryUsage);
AddToList("Peak Memory Usage :" + PeakMemoryUsage);
AddToList("Firmware Version :" + FirmwareVersion);
AddToList("Hardware Version :" + HardwareVersion);
AddToList("Manufacturer :" + Manufacturer);
AddToList("Total Memory :" + TotalMemory);
AddToList("Power Source:" + powerSource.ToString());
AddToList("Operating System: Windows Phone " + OSVersion.ToString());

}
public void AddToList(string Property)
{
lstboxDeviceInfo.Items.Add(Property);
}

take a look at here for more info

How can I get User Friendly version name of Windows like 'Windows 10 Pro' from UWP

Windows Community toolkit has helpers which has a static utility class SystemInformation.

It provides an easy way to access application as well as system information like OperatingSystem,OperatingSystemArchitecture and OperatingSystemVersion among others which can provide the exact information that you need.

Since this toolkit is maintained and updated very well you can be sure of any cases for future releases

How to get the name of OS in which the code is running using C#?

You could get the Operating System 's friendly name by using WMI.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
String operatingSystem = String.Empty;

foreach (ManagementObject query in searcher.Get())
{
operatingSystem = query["Caption"].ToString();
break;
}

You could use WMI Code Creator, a great tool from Microsoft to generate WMI queries.

Get Windows OS name from XP and up

Starting from Windows Vista, the Major-Number of the release was 6. Windows Vista has 6.0, Windows 7 has 6.1 and Windows 8 has 6.2.

See here for an overview.

EDIT

switch (vs.Major)
{
case 3:
Console.WriteLine("Windows NT 3.51");
break;
case 4:
Console.WriteLine("Windows NT 4.0");
break;
case 5:
if (vs.Minor == 0)
Console.WriteLine("Windows 2000");
else
Console.WriteLine("Windows XP");
break;
case 6:
if(vs.Minor == 0)
Console.WriteLine("Windows Vista");
else if(vs.Minor == 1)
Console.WriteLine("Windows 7");
else if(vs.Minor == 2)
Console.WriteLine("Windows 8")
break;
}

How can I find the Windows Edition name

You can get the operating system name from the registry but you need to query WMI for the architecture and the service pack information:

using System.Diagnostics;
...
private string GetOperatingSystemInfo()
{
RegistryKey operatingSystemKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string operatingSystemName = operatingSystemKey.GetValue("ProductName").ToString();

ConnectionOptions options = new ConnectionOptions();
// query any machine on the network
ManagementScope scope = new ManagementScope("\\\\machineName\\root\\cimv2", options);
scope.Connect();
// define a select query
SelectQuery query = new SelectQuery("SELECT OSArchitecture, CSDVersion FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

string osArchitecture = "";
string osServicePack = "";

foreach (ManagementObject mo in searcher.Get())
{
osArchitecture = mo["OSArchitecture"].ToString();
osServicePack = mo["CSDVersion"].ToString();
}
return operatingSystemName + " " + osArchitecture + " " + osServicePack;
}

If you want more information from WMI, be sure to take a look at the Win32_OperatingSystem class on MSDN.

Get current version OS in Windows 10 in C#

Add application manifest to your application and add the supportedOS Id of Windows 8.1 and Windows 10 to the manifest:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
</application>
</compatibility>

Now Environment.OSVersion includes the correct data for Windows 8.1 and Windows 10 and not 6.2 to indicate you run Windows 8. This is a change since Windows 8.1.



Related Topics



Leave a reply



Submit