加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 03:45:56 所属栏目:百科 来源:网络整理
导读:有没有任何Win32 API在特定的时间唤醒已关闭的系统?我看到一个名为Autopower On的程序,它能够在指定的时间为系统供电. 解决方法 从网站获得了 the below post.任何身体都试过了吗? 在框架中没有什么,所以你必须要“PInvoke”一点. 您需要调用的API是Create
有没有任何Win32 API在特定的时间唤醒已关闭的系统?我看到一个名为Autopower On的程序,它能够在指定的时间为系统供电.

解决方法

从网站获得了 the below post.任何身体都试过了吗?

在框架中没有什么,所以你必须要“PInvoke”一点.
您需要调用的API是CreateWaitableTimer和SetWaitableTimer.
以下是一个完整的(Q& D)样本,说明如何设置
系统从sleep / hibernate唤醒使用上面的Win32 API.
请注意,这里我设置的相对唤醒时间为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,IntPtr.Zero,true);
            uint INFINITE = 0xFFFFFFFF;
            int ret = WaitForSingleObject(handle,INFINITE);
            MessageBox.Show("Wake up call");
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读