是否有任何 Win32 API 可以在特定时间唤醒已关闭的系统?我见过一个名为 Autopower On 的程序,它可以在指定的时间启动系统。
最佳答案
得到 the below post从一个网站。有人试过这个吗?
框架中没有任何内容,因此您必须“PInvoke”一下。 您需要调用的 API 是 CreateWaitableTimer 和 SetWaitableTimer。 以下是一个完整的 (Q&D) 示例,说明了如何设置 使用以上 Win32 API 将系统从 sleep /休眠状态唤醒。 请注意,这里我将相对唤醒时间设置为 300000000 nSecs。 这意味着计算机将被唤醒(假设他睡着了或 休眠)在设置定时器后 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#:如何唤醒已关闭的系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4061844/