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?
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; } }
absalomMaybe the following c# snippet helps
Thanks!