Created
January 17, 2023 12:44
-
-
Save emoacht/b253fc8775acf0f533708ab94b1d9349 to your computer and use it in GitHub Desktop.
Enumerate monitor connections by WMI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Management; | |
public static class MonitorHelper | |
{ | |
public static IEnumerable<MonitorConnection> EnumerateMonitorConnections() | |
{ | |
var @class = new ManagementClass(@"root\wmi:WmiMonitorConnectionParams"); | |
foreach (var @object in @class.GetInstances().Cast<ManagementObject>()) | |
{ | |
yield return new MonitorConnection( | |
(bool)@object["Active"], | |
(string)@object["InstanceName"], | |
(D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY)(uint)@object["VideoOutputTechnology"]); | |
} | |
} | |
} | |
public record MonitorConnection(bool IsActive, string InstanceName, D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY OutputTechnology); | |
public enum D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY : int | |
{ | |
D3DKMDT_VOT_UNINITIALIZED = -2, | |
D3DKMDT_VOT_OTHER = -1, | |
D3DKMDT_VOT_HD15 = 0, | |
D3DKMDT_VOT_SVIDEO = 1, | |
D3DKMDT_VOT_COMPOSITE_VIDEO = 2, | |
D3DKMDT_VOT_COMPONENT_VIDEO = 3, | |
D3DKMDT_VOT_DVI = 4, | |
D3DKMDT_VOT_HDMI = 5, | |
D3DKMDT_VOT_LVDS = 6, | |
D3DKMDT_VOT_D_JPN = 8, | |
D3DKMDT_VOT_SDI = 9, | |
D3DKMDT_VOT_DISPLAYPORT_EXTERNAL = 10, | |
D3DKMDT_VOT_DISPLAYPORT_EMBEDDED = 11, | |
D3DKMDT_VOT_UDI_EXTERNAL = 12, | |
D3DKMDT_VOT_UDI_EMBEDDED = 13, | |
D3DKMDT_VOT_SDTVDONGLE = 14, | |
D3DKMDT_VOT_MIRACAST = 15, | |
D3DKMDT_VOT_INDIRECT_WIRED = 16, | |
D3DKMDT_VOT_INTERNAL = unchecked((int)0x80000000), | |
D3DKMDT_VOT_SVIDEO_4PIN = D3DKMDT_VOT_SVIDEO, | |
D3DKMDT_VOT_SVIDEO_7PIN = D3DKMDT_VOT_SVIDEO, | |
D3DKMDT_VOT_RF = D3DKMDT_VOT_COMPOSITE_VIDEO, | |
D3DKMDT_VOT_RCA_3COMPONENT = D3DKMDT_VOT_COMPONENT_VIDEO, | |
D3DKMDT_VOT_BNC = D3DKMDT_VOT_COMPONENT_VIDEO, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment