How can I know which HDMI port is plugged in?

耗尽温柔 提交于 2021-01-29 07:55:52

问题


I have a computer with a dual hdmi output. I would like to detect which one is plugged in when I connect a monitor to either to one of them.

It can be either with the help of registry, powershell or C# code, or anything. As long as it's not C++.

I've tried various wmi methods. Searched the registry for anything that would specify a hdmi port. But found nothing so far.

This stackoverflow answer (Detect/identify the port (HDMI, other) the monitor is connected to in Windows 7/8/10 Win32 C++) is the only one I found regarding my need, but I can't handle c++ so from now on I'm stuck.

Thanks everyone


回答1:


Try this in powershell.

$objWMi = get-wmiobject -namespace root\WMI -computername localhost -Query "Select * from WmiMonitorConnectionParams"

foreach ($obj in $objWmi)
{
    write-host "Active:" $obj.Active
    write-host "InstanceName:" $obj.InstanceName
    write-host "VideoOutputTechnology:" $obj.VideoOutputTechnology
    write-host
    write-host "########"
    write-host
}

The WmiMonitorConnectionParams class has VideoOutputTechnology property which returns the following:

    typedef enum _D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY { 
  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,
#if (DXGKDDI_INTERFACE_VERSION >= DXGKDDI_INTERFACE_VERSION_WDDM1_3_M1)
  D3DKMDT_VOT_MIRACAST              = 15,
#endif 
  D3DKMDT_VOT_INTERNAL              = 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
} D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY;


来源:https://stackoverflow.com/questions/58509558/how-can-i-know-which-hdmi-port-is-plugged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!