C#:如何唤醒已关机的系统?

是否有任何Win32 API用于唤醒在特定时间关闭的系统? 我见过一个名为Autopower On的程序,可以在指定的时间启动系统。

从网站上得到以下post 。 有人试过这个吗?

框架中没有任何东西,所以你必须“PInvoke”一点。 您需要调用的API是CreateWaitableTimer和SetWaitableTimer。 以下是一个完整的(Q&D)示例,演示了如何使用上面的Win32 API将系统设置为从睡眠/hibernate状态唤醒。 请注意,这里我设置的相对唤醒时间为3000000 nSecs。 这意味着计算机将在设置计时器后30秒内唤醒(假设他正在睡觉或hibernate)。 有关SetWaitableTimer及其参数的详细信息,请参阅MSDN文档。

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"); } } } 

此Wake on LAN(WOL)代码项目post可能有用(主板和NIC都必须支持WOL)

一旦你真正关闭了你的计算机(不睡觉或hibernate),你就无法直接从C#,C ++代码中唤醒它。 在所有操作系统本身关闭之后。

唯一的机会是你的主板支持某种计时器机制。 并且有一些C ++函数能够将一些标志写入BIOS并设置该计时器。

使用Windows“计划任务”菜单。 看到:

http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/

您创建一个要在唤醒时运行的程序,然后手动将其输入到Windows计划任务列表中,这是第一次在特定时间后唤醒。

当你编程唤醒时,我不确定你是否需要你的程序来调用Windows API以阻止它再次被唤醒,同样如果你希望你的程序在启动另一个已调度的任务再次唤醒之后关闭PC。 需要研究一下这些Windows API。