I've to make a simple program that reports to a server the state of the monitor (is it on/off or simply if it's not connected). So far I'm using this method I found on another discussion, but it simply returns to me true every times, even if I've disconnected my monitor.
public static Boolean isMonitorActive()
{
Boolean active = false;
var query = "select * from WmiMonitorBasicDisplayParams";
using (var wmiSearcher = new ManagementObjectSearcher("\\root\\wmi", query))
{
var results = wmiSearcher.Get();
foreach (ManagementObject wmiObj in results)
{
// get the "Active" property and cast to a boolean, which should
// tell us if the display is active. I've interpreted this to mean "on"
active = (Boolean)wmiObj["Active"];
return active;
}
}
return active;
}
I've to check the status of the monitor every 2-3 minutes, so I need to use something different from the MonitorCout variable in System, because it's initialized and remain the same from the beginning to end of the program (If I'm not mistaken). Thanks for reading and helping.
来源:https://stackoverflow.com/questions/16668075/check-if-the-monitor-is-connected