Windows Entertainment and Connected Home

How to organize, access and enjoy all of your media in and around your home

Can I trigger a script on the "Turn off Display" event?

  • rated by 0 users
  • This post has 3 Replies |
  • 2 Followers
Page 1 of 1 (4 items)
  •  

    I wrote a VB app that can power off my Samsung display and would like to trigger it when windows turns off my display (from the power management settings).   How can I hook it?

  •  
    Monitoring for GUID_MONITOR_POWER_ON states using the RegisterPowerSettingNotification function.
    Mikinho | Missing Remote | @mikinho | Microsoft Windows Entertainment and Connected MVP
  •  

     Maybe the following c# snippet helps (I think the orginal code came from MSDN):

        class Program
        {
            static ManagementEventWatcher _watcher;
     
            static void Main(string[] args)
            {
                WqlEventQuery query = new WqlEventQuery("Win32_PowerManagementEvent");
                _watcher = new ManagementEventWatcher(query);
                _watcher.EventArrived += new EventArrivedEventHandler(watcher_Event);
                _watcher.Start();

               do something ..

             }

     

            static void watcher_Event(object sender, EventArrivedEventArgs e)
            {
                    int eventType = Convert.ToInt32(e.NewEvent.Properties["EventType"].Value);
                    switch (eventType)
                    {
                        case 4:  // PBT_APMSUSPEND
                            ...
                            break;
                        case 18:  // PBT_APMRESUMEAUTOMATIC
                            // don't use PBT_APMRESUMESUSPEND because user isn't always present
                            ...
                            break;
                        case 7:  // PBT_APMRESUMESUSPEND
                            ...
                            break;
                        default:
                            ...
                            break;
                    }
            }
     

     

  •  

    absalom
    Maybe the following c# snippet helps

    Thanks!

Page 1 of 1 (4 items)