🟣 C# / .NET 6+

Get Connected Monitors Report (C#)

Queries Win32_DesktopMonitor via WMI (System.Management) and prints Connected Monitors to the console.

By WindowsScripting.com · 1017 B
GetDesktopMonitorReport.cs
// GetDesktopMonitorReport.cs
//
// Reports Connected Monitors via WMI (Win32_DesktopMonitor).
//
// Requires the System.Management package:
//   dotnet new console -o DesktopMonitorReport
//   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 Name, ScreenWidth, ScreenHeight FROM Win32_DesktopMonitor");
int count = 0;

foreach (ManagementObject item in searcher.Get())
{
    Console.WriteLine($"Name: {item["Name"]}");
    Console.WriteLine($"ScreenWidth: {item["ScreenWidth"]}");
    Console.WriteLine($"ScreenHeight: {item["ScreenHeight"]}");
    Console.WriteLine(new string('-', 40));
    count++;
}

if (count == 0)
{
    Console.WriteLine("No Connected Monitors found.");
}
else
{
    Console.WriteLine($"\n{count} Connected Monitors found.");
}