C#:如何唤醒已经关闭的系统?
是否有任何 Win32 API 用于在特定时间唤醒已关闭的系统?我见过一个名为 Autopower On 的程序,它能够在指定的时间打开系统电源。
Is there any Win32 API for waking up a system that has been shut down, at a specific time? I have seen a program named Autopower On which is able to power the system on at a specified time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
得到以下帖子来自某个网站。有人尝试过这个吗?
框架中没有任何内容,因此您必须“PInvoke”一下。
您需要调用的 API 是 CreateWaitableTimer 和 SetWaitableTimer。
以下是一个完整的(Q&D)示例,说明了如何设置
使用上述 Win32 API 将系统从睡眠/休眠状态唤醒。
请注意,这里我将相对唤醒时间设置为 300000000 纳秒。
这意味着计算机将被唤醒(假设他睡着了或者
设置定时器后 30 秒内休眠)。
有关 SetWaitableTimer 及其参数的详细信息,请参阅 MSDN 文档。
Got the below post from a site. Any body tried this?
Nothing in the framework, so you'll have to "PInvoke" a bit.
The API's you need to call are CreateWaitableTimer and SetWaitableTimer.
Following is a complete (Q&D) sample that illustrates how you can set a
system to be awoken from sleep/hibernate using above Win32 API's.
Note that here I'm setting a relative wakeup time of 300000000 nSecs.
That means that the computer will wake-up (supposing he's asleep or
hibernating) within 30 seconds after setting the timer.
Consult the MSDN docs for details on SetWaitableTimer and it's arguments.
这个 Wake on LAN (WOL) 代码项目帖子可能有用(主板并且网卡必须支持WOL)
This Wake on LAN (WOL) code project post might be of use (Both motherboard and NIC must support WOL)
一旦您实际关闭计算机(不是睡眠或休眠),您就无法直接从 C#、C++ 代码中唤醒它。毕竟操作系统本身已关闭。
唯一的机会是您的主板支持某种计时器机制。并使用一些 C++ 函数能够将一些标志写入 BIOS 并设置计时器。
Once you actually shut down your computer(not sleeping or hibernating) you can't wake it up from C#, C++ code directly. After all the OS itself is closed.
The only chance would be for your motherboard to support some kind of timer mechanism. And with some C++ function to be able to write some flags into the BIOS and set that timer.
使用 Windows 的“计划任务”菜单。请参阅:
http://www. howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/
您创建一个要在唤醒时运行的程序,然后手动将其输入到 Windows 计划任务中列表在特定时间后第一次唤醒。
当你的程序唤醒时,我不确定你的程序是否需要调用Windows API来
停止再次唤醒它,如果您希望程序在启动另一个计划任务以再次唤醒它后关闭电脑电源,则同上。需要研究一下有哪些 Windows API 可以用于此目的。
Use the windows "Scheduled Task" menu. See:
http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/
You create a program that you want to run upon wake up and then manually enter it into the windows scheduled task list for the first time to wake after a specific time.
When you program awakens, I am not sure if you need your program to call a Windows API to
stop it being awoken again, ditto if you want your program to power off the PC after starting another sceduled task to awaken it again. Need to reserach what windows APIs there are for this.