Is there any Win32 API for waking up a system that has been shut down, at a specific time? I have seen a program named Autopower On which is able to power the system on at a specified time.
-
3When would you run this C# program? While the computer is off? Or before it is turned off? – Gabe Oct 31 '10 at 04:29
-
i run this program before it is turned off. – Vishnu Pradeep Oct 31 '10 at 04:31
-
You need to dig into ACPI. A bit of googling says you can access this with WMI, but I'm not sure to what extent. – Brad Oct 31 '10 at 04:33
-
@Brad: what should i google for ? tell me some keywords to search. – Vishnu Pradeep Oct 31 '10 at 04:58
-
1The Auto Power-on program (http://lifsoft.com/) does not work when a computer has been shut down. It only works on sleeping/hibernating computers. – Gabe Oct 31 '10 at 05:21
-
@vishnu, I already told you in my comment... .NET and ACPI but it looks like you were able to figure out a solution. – Brad Oct 31 '10 at 15:31
4 Answers
Got the below post from a site. Any body tried this?
Nothing in the framework, so you'll have to "PInvoke" a bit. The API's you need to call are CreateWaitableTimer and SetWaitableTimer. Following is a complete (Q&D) sample that illustrates how you can set a system to be awoken from sleep/hibernate using above Win32 API's. Note that here I'm setting a relative wakeup time of 300000000 nSecs. That means that the computer will wake-up (supposing he's asleep or hibernating) within 30 seconds after setting the timer. Consult the MSDN docs for details on SetWaitableTimer and it's arguments.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Willys
{
class Program
{
[DllImport("kernel32.dll")]
public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes,
bool bManualReset, string lpTimerName);
[DllImport("kernel32.dll")]
public static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long
pDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr
lpArgToCompletionRoutine, bool fResume);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
public static extern Int32 WaitForSingleObject(IntPtr handle, uint
milliseconds);
static void Main()
{
SetWaitForWakeUpTime();
}
static IntPtr handle;
static void SetWaitForWakeUpTime()
{
long duetime = -300000000; // negative value, so a RELATIVE due time
Console.WriteLine("{0:x}", duetime);
handle = CreateWaitableTimer(IntPtr.Zero, true, "MyWaitabletimer");
SetWaitableTimer(handle, ref duetime, 0, IntPtr.Zero, IntPtr.Zero, true);
uint INFINITE = 0xFFFFFFFF;
int ret = WaitForSingleObject(handle, INFINITE);
MessageBox.Show("Wake up call");
}
}
}

- 84,912
- 12
- 139
- 238

- 2,087
- 2
- 29
- 56
-
4I edited the program so it works. I've verified that it wakes my computer up from sleep and hibernation. I don't expect it to wake up from being shutdown, however. – Gabe Oct 31 '10 at 05:18
-
I have tried this code on windows 8 desktop and tablet but it doesnt work. Does it have to do something with my device supporting this feature or all devices would support the wake up option? I had a look at the Allow wake timers option under the sleep option in advanced power settings but changing that too on desktop dint work and tablet dint have the option at all – Aster Veigas Oct 29 '13 at 18:03
-
On that site there were caveats that you also need to ensure you don't require a password to be entered to wake it/on wake, and in the Sleep settings, to Allow Wake Timers. – vapcguy Feb 23 '17 at 19:23
This Wake on LAN (WOL) code project post might be of use (Both motherboard and NIC must support WOL)

- 295,962
- 43
- 465
- 541
Once you actually shut down your computer(not sleeping or hibernating) you can't wake it up from C#, C++ code directly. After all the OS itself is closed.
The only chance would be for your motherboard to support some kind of timer mechanism. And with some C++ function to be able to write some flags into the BIOS and set that timer.

- 6,540
- 2
- 41
- 65
Use the windows "Scheduled Task" menu. See:
http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/
You create a program that you want to run upon wake up and then manually enter it into the windows scheduled task list for the first time to wake after a specific time.
When you program awakens, I am not sure if you need your program to call a Windows API to stop it being awoken again, ditto if you want your program to power off the PC after starting another sceduled task to awaken it again. Need to reserach what windows APIs there are for this.

- 114
- 3
-
1This is a non-programming answer which would be suitable for SuperUser. It doesn't answer the programming question which was asked, though, which requires configuring the wakeup from C#. – Ben Voigt Nov 23 '14 at 00:38