安排机器唤醒
以编程方式使 Windows XP(或更高版本)计算机在特定时间唤醒的最佳方法是什么? (理想情况下,很像 Media Center 如何自动启动来录制特定的电视节目)
我有一个 Windows 服务(用 C# 编写),并且我希望该服务能够使其托管的计算机在预定时间启动。
是否需要配置任何 BIOS 设置或先决条件(例如 ACPI)才能使其正常工作?
该机器将使用拨号或 3G 无线调制解调器,因此不幸的是它不能依赖 LAN 唤醒。
What's the best way to programmatically cause a Windows XP (or above) machine to wake up at a specific time. (Ideally a lot like how Media Center can start up automatically to record a particular TV program)
I've got a Windows service (written in C#) and I'd like this service to be able to cause the machine it is hosted on to start up at predetermined times.
Are there any BIOS settings or prerequisites (eg. ACPI) that need to be configured for this to work correctly?
This machine would be using dialup or 3G wireless modem, so unfortunately it can't rely on Wake on LAN.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用可等待计时器 从挂起或休眠状态唤醒。 据我所知,无法以编程方式从正常关闭模式(软关闭/S5)唤醒,在这种情况下,您需要在 BIOS 中指定 WakeOnRTC 警报。 要使用 C# 中的可等待计时器,您需要 pInvoke。 导入声明为:
您可以按以下方式使用这些函数:
然后,您可以使用返回的句柄作为参数,使用
CancelWaitableTimer
取消可等待计时器。您的程序可以使用 pInvoke 休眠和睡眠:
您的系统可能不允许程序让计算机进入休眠状态。 您可以调用以下方法来允许休眠:
You can use waitable timers to wake from a suspend or hibernate state. From what I can find, it is not possible to programmatically wake from normal shut down mode (soft off/S5), in that case, you need to specify a WakeOnRTC alarm in BIOS. To use waitable timers from C#, you need pInvoke. The import declarations are:
You can use those functions in the following way:
You can then cancel the waitable timer with
CancelWaitableTimer
, using the returned handle as an argument.Your program can hibernate and sleep using pInvoke:
Your system may not allow programs to let the computer enter hibernation. You can call the following method to allow hibernation:
Win7中的任务调度程序taskschd.msc(我相信XP也是如此)可以设置为在不同的触发器上唤醒系统。 这些触发器可以是计划、时间、事件等。
至少在 Win7 中,您需要将“允许唤醒计时器”设置为“启用”才能使其工作。 此设置位于...
--> 控制面板\硬件和声音\电源选项
单击 - “编辑计划设置”
单击 - “更改高级电源设置”
展开 - “睡眠”
展开 - “允许唤醒计时器”
The task scheduler program in Win7, taskschd.msc (and I beleive XP as well) can be set to wake the system on different triggers. Those triggers can be schedule, time, event, etc.
In at least Win7, you need to set "Allow Wake Timers" to 'Enabled' for this to work. This setting is found under...
--> Control Panel\Hardware and Sound\Power Options
click - "Edit Plan Settings"
click - "Change advanced power setting"
expand - "Sleep"
Expand - "Allow Wake timers"
最好的选择是使用LAN唤醒功能。 这将需要另一台机器发送特殊类型的数据包来唤醒您的机器。
如果您的计算机未连接到网络,或者由于某种原因您不想将此逻辑移动到另一台计算机上,这将没有帮助。 但对于拥有多台计算机并希望以编程方式唤醒它们的某些配置来说,它非常有用。
Your best bet is using Wake on LAN capability. This will require another machine to send a packet of a special kind to wake your machine up.
This will not be helpful if your machine is not connected to the network or you for some reason don't wasnt to move this logic onto another machine. But it's useful for some configurations where you have multiple machines and want to wake them up programmatically.
有些机器有 BIOS 闹钟,可以设置在特定时间唤醒计算机。 应该可以对这个时钟进行编程,但我不知道具体细节。
编辑:我发现这个程序应该让你设置时间。 它是在 Linux 下用 C 语言编写的,但也许它可以给你一些提示。
不过警告:在尝试直接更改 BIOS 设置之前,请务必记下 BIOS 屏幕上的每个设置,因为如果出现错误,BIOS 可能会恢复为出厂状态默认,您可能需要按原样再次设置。
Some machines have a BIOS alarm clock that can be set to wake up the computer at a certain hour. It should be possible to program this clock, but I don't know the specific details.
Edit: I found this program that should let you set the time. It's in C, under Linux, but maybe it can give you some hints.
A warning though: before trying anything that changes the BIOS settings directly be sure to write down every setting from BIOS screens, because in case of an error the BIOS might revert to factory default and you might need to set it up again as it was.