I need to detect the number of monitors that are physically connected to the computer (to decide if the screen configuration is in single, extended, or duplicate mode).
Both
System.Windows.Forms.Screen.AllScreens.Length
and System.Windows.Forms.SystemInformation.MonitorCount
return the number of virtual screens (desktops).
I need that if there are 2+ monitors connected to the PC, I can decide between duplicate/extended mode using this value, but I can't decide if there is only one physical monitor connected to the PC, and therefore the screen configuration is in single screen mode.
Try the following:
Answer found on the following question:
WMI Get All Monitors Not Returning All Monitors
Update
Try the following function it detects unplugging the monitor:
Here are a list for the status: https://msdn.microsoft.com/en-us/library/aa394122%28v=vs.85%29.aspx
Maybe you need to increase the counter on a other statuscode as well. Check the link for more information.