如果检测显示器是C# [英] Detect if monitor is on c#

查看:122
本文介绍了如果检测显示器是C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时,如果用户的显示器已打开使用C#可以检测?

Is it possible to detect if the users monitor is turned on using c#?

SP

我'以前也发现了这个帖子是有益

I've also discovered this post which is helpfull

http://www.netframeworkdev.com/net-base-class-library/msmonitorclass-2114.shtml

推荐答案

WMI可能的帮助。

在Vista中+,有的 WmiMonitorBasicDisplayParams 类,其中的活动属性告诉你,如果显示的是活动的。

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"];
    }
}

这篇关于如果检测显示器是C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆