Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting an application when Windows wakes up from sleep mode

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).

like image 335
Rodrigo Osvaldo Grijalva López Avatar asked Nov 10 '12 02:11

Rodrigo Osvaldo Grijalva López


1 Answers

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.

like image 176
lukiffer Avatar answered Nov 04 '22 12:11

lukiffer