Turning off screen on Windows 10

Joined
Aug 11, 2017
Messages
2
Reaction score
0
We are realying on Microsoft.WindowsAPICodePack-Core to detect a screen off event on Windows 10 - (MonitorOnChanged event, PowerManager.IsMonitorOn). However, it happens that the screen actually turns black 5 seconds before we recieve an actual event. This does not happen on Windows 8, so we are assuming that this must be an addition to Windows 10 power settings/options, but have not been able to track it down. Does anyone know a bit more about this?
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
Hi Miko,

Welcome to the Forum.

What script / program code have you created to take advantage of the call to PowerManager.IsMonitorOn?

Back in the days of Windows Vista, and Windows 7 too Power Manager scripts were predominantly coded in either C# or VB as opposed to PowerShell. Are you attempting to use an older Script withing the PowerShell environment?

If you are using a script provided by a third party opposed to one you coded yourself, there is also a high probability it includes a time delay on reporting events? That used to be a popular thing to do in coding such management style programs, because the older Shell programs unlike PowerShell were not able to pipe results from one Command to another instantaneously, but instead had to wait for all result sets to complete. Thus you may find a block of code hiding in your program / script that uses a conditional loop to force a timeout of reporting an event.

To give further advice on your stated issue, I'd really need to get some answers to my initial questions, and if possible review the code you are working from.

In terms of PowerShell though, you could probably play around with the Get-WmiObject cmdlet.

Here is a sample of what you can do using that cmdlet within PowerShell:

Code:
Clear-Host
Get-WmiObject WmiMonitorID -Namespace root\wmi |
  Select @{
    n = "Manufacturer"
    e = { [System.Text.Encoding]::ASCII.GetString($_.ManufacturerName -ne 00) }
  },
  @{
    n = "Model"
    e = { [System.Text.Encoding]::ASCII.GetString($_.UserFriendlyName -ne 00) }
  } | Format-Table

sample.png

That assumes this.object is in a state of on hence the -ne 00
 
Joined
Aug 11, 2017
Messages
2
Reaction score
0
Thanks for the answer. This is the code i use.

using Microsoft.WindowsAPICodePack.ApplicationServices;

// . . .
PowerManager.IsMonitorOnChanged += new EventHandler(MonitorOnChanged);
// . . .
void MonitorOnChanged(object sender, EventArgs e)
{
var onOrOff = PowerManager.IsMonitorOn;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top