1

I am using these system notifications to detect a power off or power on event for windows. Now I am trying to delay power off event and execute one function before that So how is that possible.

     [DllImport(@"User32", EntryPoint = "RegisterPowerSettingNotification",
          CallingConvention = CallingConvention.StdCall)]
     private static extern IntPtr RegisterPowerSettingNotification(
         IntPtr hRecipient,
         ref Guid PowerSettingGuid,
         Int32 Flags);

     [DllImport(@"User32", EntryPoint = "UnregisterPowerSettingNotification",
          CallingConvention = CallingConvention.StdCall)]
     private static extern bool UnregisterPowerSettingNotification(
         IntPtr handle);
Juan
  • 588
  • 1
  • 8
  • 25
  • [This one](http://stackoverflow.com/questions/5217246/how-to-delay-shutdown-and-run-a-process-in-window-service) is probably very related. – dotNET Oct 21 '14 at 06:54
  • 1
    Maybe this can help: http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208%28v=vs.85%29.aspx (`SetThreadExecutionState` function). Recommended by MSDN to use from `WM_POWERBROADCAST` message handler. – Alex F Oct 21 '14 at 07:00
  • @dotNET can this help me when machine is going in sleep mode? – gayatri Kadam Oct 21 '14 at 07:22
  • Hello..thanks for reply but I do not want to use windows service to delay the system sleep event..can anyone help me with that.. – gayatri Kadam Oct 28 '14 at 11:46
  • I am using PowerClearRequest, PowerSetRequest functions to awake system back from sleep mode but its not working.. – gayatri Kadam Oct 28 '14 at 11:54

0 Answers0