Is it possible to detect whether a monitor attached to a Windows PC is actively displaying a certain input?

StackOverflow https://stackoverflow.com/questions/21737005

  •  10-10-2022
  •  | 
  •  

Question

I'm developing a Windows application that supports remote displays through VNC. Normally the remote displays will be the only visual interface. However, there will be cases where a user will want to view the application with a physical monitor. If a physically attached monitor is connected and switched to a specific input (could be DVI or HDMI), I need to be able to detect that and turn off VNC. Is it possible to detect whether an attached monitor is actively displaying a certain input?

I know that I can get some information about the attached monitors with Screen.AllScreens but nothing therein seems to quite match what I need. Is there perhaps some method exposed by the Windows API that could give me this information? Can the necessary information be determined from VESA/DDC?

Was it helpful?

Solution

I don't have any experience developing a VNC application, but maybe a suggestion might start you off on the right path.

Download wmiexplorer

  1. Run the program
  2. Here you can explorer different classes in WMI, which will be the lowest level I think you're going to get
  3. Go to the Query tab and enter the query: "select * from Win32_DesktopMonitor"

I think this is the information you can use to figure out information about your monitors. (I'm not sure what classes have information that relates to monitors)

In particular, check out Availability for the Win32_DesktopMonitor class.

Update

Running this query on a remote machine Description and DeviceID and Name came back as "Default Monitor." On my real machine, it came back as "Generic PnP Monitor" as well as had a MonitorManufacturer set, where as the remote machine didn't. You could even go as far as comparing the queried monitor with Screen resolution or maybe SystemName returned in the query vs. the system name of the computer running the application.

Use the ManagementObjectSearcher to execute WMI queries.

Edit

You could also do the mapping/cross-checking of devices like the example shown here does. Notice the ClassGUID is the same between MonitorDesktop and PnPEntity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top