Turning off screen on Windows 10

Discussion in 'Programming and Windows PowerShell' started by miko, Aug 11, 2017.

  1. miko

    miko

    Joined:
    Aug 11, 2017
    Messages:
    2
    Likes Received:
    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?
     
    miko, Aug 11, 2017
    #1
    1. Advertisements

  2. miko

    Regedit32 Moderator

    Joined:
    Mar 4, 2016
    Messages:
    2,536
    Likes Received:
    727
    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
     
    Regedit32, Aug 11, 2017
    #2
    1. Advertisements

  3. miko

    miko

    Joined:
    Aug 11, 2017
    Messages:
    2
    Likes Received:
    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;

    }
     
    miko, Aug 14, 2017
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. IanMc

    Turning off High Contrast

    IanMc, Oct 2, 2015, in forum: Windows 10 Support
    Replies:
    4
    Views:
    7,435
    Jon C.
    Aug 13, 2016
  2. ottiliegirl

    Display Turning Off

    ottiliegirl, Oct 16, 2015, in forum: Windows 10 Support
    Replies:
    35
    Views:
    2,435
    ottiliegirl
    Oct 18, 2015
  3. kurt pedersen

    Turning off touch pad in favor of a mouse

    kurt pedersen, Oct 28, 2015, in forum: Windows 10 Support
    Replies:
    2
    Views:
    704
    davehc
    Oct 28, 2015
  4. Catfish

    Turning off power during download of update

    Catfish, Mar 11, 2016, in forum: Windows 10 Support
    Replies:
    1
    Views:
    526
    Trouble
    Mar 11, 2016
  5. ler

    Second Monitor keeps turning on and off

    ler, Mar 13, 2016, in forum: Windows 10 Support
    Replies:
    0
    Views:
    1,401
  6. salcas

    SOLVED Wifi Keeps Turning Off

    salcas, May 13, 2016, in forum: Networking
    Replies:
    11
    Views:
    7,801
    pingiii
    Dec 3, 2016
  7. Mateoski
    Replies:
    4
    Views:
    1,216
    Mateoski
    May 14, 2016
  8. Mic User

    Computer randomly turning off unexpectedly.

    Mic User, May 18, 2016, in forum: Windows 10 Support
    Replies:
    1
    Views:
    621
    denis lacroix
    May 19, 2016
Loading...