Here’s how to programmatically determine the Windows OS you are using. I will make use of the ManagementObjectSearcher class here
C#
using System;
using System.Management;
namespace ConsoleApplication1
{
class Program
{
public static void Main()
{
string winos = "Select Name from Win32_OperatingSystem";
ManagementObjectSearcher mos =
new ManagementObjectSearcher(winos);
foreach (ManagementObject mo in mos.Get())
{
Console.WriteLine("OS Name: {0}", mo["Name"]);
}
Console.ReadLine();
}
}
}
VB.NET
Imports System
Imports System.Management
Namespace ConsoleApplication1
Friend Class Program
Public Shared Sub Main()
Dim winos As String = "Select Name from Win32_OperatingSystem"
Dim mos As New ManagementObjectSearcher(winos)
For Each mo As ManagementObject In mos.Get()
Console.WriteLine("OS Name: {0}", mo("Name"))
Next mo
Console.ReadLine()
End Sub
End Class
End Namespace
Here the Win32_OperatingSystem WMI class represents a Windows-based operating system installed on a computer.
OUTPUT
Tweet
No comments:
Post a Comment