🟣 C# / .NET 6+

Get Operating System Info Report (C#)

Queries Win32_OperatingSystem via WMI (System.Management) and prints Operating System Info to the console.

By WindowsScripting.com · 1.2 KB
GetOperatingSystemReport.cs
// GetOperatingSystemReport.cs
//
// Reports Operating System Info via WMI (Win32_OperatingSystem).
//
// Requires the System.Management package:
//   dotnet new console -o OperatingSystemReport
//   dotnet add package System.Management
//   (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.

using System;
using System.Management;

var searcher = new ManagementObjectSearcher("SELECT Caption, Version, OSArchitecture, LastBootUpTime, FreePhysicalMemory FROM Win32_OperatingSystem");
int count = 0;

foreach (ManagementObject item in searcher.Get())
{
    Console.WriteLine($"Caption: {item["Caption"]}");
    Console.WriteLine($"Version: {item["Version"]}");
    Console.WriteLine($"OSArchitecture: {item["OSArchitecture"]}");
    Console.WriteLine($"LastBootUpTime: {item["LastBootUpTime"]}");
    Console.WriteLine($"FreePhysicalMemory: {item["FreePhysicalMemory"]}");
    Console.WriteLine(new string('-', 40));
    count++;
}

if (count == 0)
{
    Console.WriteLine("No Operating System Info found.");
}
else
{
    Console.WriteLine($"\n{count} Operating System Info found.");
}