开发者

Detect if monitor is on c#

开发者 https://www.devze.com 2023-01-19 10:42 出处:网络
Is it possible to detect if the users monitor is 开发者_JAVA百科turned on using c#?WMI might help.

Is it possible to detect if the users monitor is 开发者_JAVA百科turned on using c#?


WMI might help.

In Vista+, there is the WmiMonitorBasicDisplayParams class, where the "Active" property tells you if the display is active.

Here's an example which works for me:

using System.Management;

// ...

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"
        var active = (Boolean)wmiObj["Active"];
    }
}


All the Active property does is tell you if Windows is using the display or not. Also DVI/HDMI will report a connection even when the display is turned off. In short, there is no method for checking other than something homemade--like hooking up a light sensor or webcam and pointing it at the monitor's power light :)

0

精彩评论

暂无评论...
验证码 换一张
取 消