I have a Windows Forms application in C #, NET Framework 3.5 (in VS 2010), and I need that once installed the app, this (the app) starts when Windows returns from sleep mode (being the app fully closed and not running in the background), even when the user needs to enter his password (in this case, after the user logs).
Asked
Active
Viewed 2,157 times
6
-
I've never worked with services and applications in the background, I thought it was important to mention it. – Rodrigo Osvaldo Grijalva López Nov 10 '12 at 02:42
1 Answers
6
You will need to have an application running to catch the event, however it doesn't have to be the full application - you can setup an application that all it does is respond to the event by opening your other app:
Microsoft.Win32.SystemEvents.PowerModeChanged += this.SystemEvents_PowerModeChanged;
private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
{
if (e.Mode == PowerModes.Resume)
{
//Execute your "payload" app here.
}
}
Without a background service running, I don't think there's a built-in hook in Windows.

lukiffer
- 11,025
- 8
- 46
- 70
-
I lied - there is a hook: http://stackoverflow.com/questions/4693689/how-to-programmatically-detect-when-the-os-windows-is-waking-up-or-going-to-sl though I'm not sure how to programmatically set it in your installer or app init. – lukiffer Nov 10 '12 at 03:03