有没有Win32 API可以在特定时间唤醒已关闭的系统?我见过一个名为Autopower On的程序,可以在指定时间开启计算机电源。
有没有Win32 API可以在特定时间唤醒已关闭的系统?我见过一个名为Autopower On的程序,可以在指定时间开启计算机电源。
从一个网站上得到了下面的帖子。有人试过这个吗?
框架中没有相应的功能,所以你需要进行“PInvoke”。 你需要调用的API是CreateWaitableTimer和SetWaitableTimer。 以下是一个完整的(Q&D)示例,演示了如何使用上述Win32 API设置系统在睡眠/休眠状态下被唤醒。 请注意,此处我设置了相对唤醒时间为300000000纳秒。这意味着计算机将在设置定时器后的30秒内被唤醒(假设它正在睡眠或休眠)。 有关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");
}
}
}
如果您实际关闭计算机(不是睡眠或休眠模式),则无法直接从C#、C ++代码中唤醒它。毕竟,操作系统本身已关闭。
唯一的可能性是您的主板支持某种定时器机制。通过一些C ++函数,能够将一些标志写入BIOS并设置该定时器。
使用Windows的"计划任务"菜单。请参见:
http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/
你创建了一个程序,希望在计算机唤醒后自动运行,并手动将其添加到Windows计划任务列表中,以便在特定时间后唤醒。
当你的程序被唤醒时,我不确定是否需要调用Windows API来停止它再次被唤醒,同样,如果你想让你的程序在启动另一个计划任务唤醒后关闭电脑,需要研究一下有哪些Windows API可用。