Detecting If The Monitor Is Powered Off

Is there any way to detect the monitor state in Windows (on or off)?

GetDevicePowerState sometimes works for monitors. If it's present, you can open the \\.\LCD device. Close it immediately after you've finished with it.

Essentially, you're out of luck—there is no reliable way to detect the monitor power state, short of writing a device driver and filtering all of the power IRPs up and down the display driver chain. And that's not very reliable either.

How to check if monitor is on or off

This is certainly not possible in cross platform Java, and to be honest isn't really possible in a reliable sense even if we resort to native code.

The (non-reliable) way to do this natively for Windows would be to use GetDevicePowerState - find it in kernel32.dll. However, from experiments I did using this function a while back I can say it definitely doesn't work with every monitor, and obviously even if this was reliable it would be a Windows-only solution.

If you do want to go down this route bearing in mind the above limitations, then use MonitorFromPoint to grab the handle to the primary monitor (pass in a 0,0 as the point and use the MONITOR_DEFAULTTOPRIMARY flag.)

Detecting if the monitor is powered off

Here is an older answer that might help: How to Determine if LCD Monitor is Turned on From Linux Command Line

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

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.



Related Topics



Leave a reply



Submit