vis*_*hnu 9 .net c# winapi windows-xp acpi
有没有醒来已关闭系统,在特定时间任意的Win32 API?我已经看到了一个名为程序的自功率在其上能够在系统上在指定时间开机.
vis*_*hnu 11
从网站获得以下帖子.有人试过这个吗?
框架中没有任何东西,所以你必须"PInvoke"一点.您需要调用的API是CreateWaitableTimer和SetWaitableTimer.以下是一个完整的(Q&D)示例,演示了如何使用上面的Win32 API将系统设置为从睡眠/休眠状态唤醒.请注意,这里我设置的相对唤醒时间为3000000 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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6875 次 |
| 最近记录: |