睡眠命令后唤醒Windows系统的命令 [英] command to wake up the windows system after sleep command
问题描述
从C#程序中,我想调用Windows命令提示符,并使系统进入睡眠状态,几秒钟后,我应该唤醒系统。我已成功使系统进入睡眠状态,但几秒钟后无法唤醒它。我试图使其进入睡眠和唤醒状态的命令是 powrprof.dll,SetSuspendState 0,1,0&&超时10&& echo Hello World。
From C# program I want to call windows command prompt and make the system to sleep and after few seconds I should wake the system. I am successful in making the system sleep but I can't wake it up after few seconds. The command that I tried for making it sleep and wake up is "powrprof.dll,SetSuspendState 0,1,0 && timeout 10 && echo "Hello World" ".
链接 http://www.groovypost。 com / howto / schedule-wake-sleep-windows-automatically / 表示回声将唤醒系统,但无法正常工作。
The link http://www.groovypost.com/howto/schedule-wake-sleep-windows-automatically/ says echo will wake the system but its not working.
推荐答案
可以使用win32 CreateWaitableTimer API。
It is possible using the win32 CreateWaitableTimer API.
- 调用系统睡眠时,创建WaitableTimer的过程必须处于活动状态。
- 示例使用pywin32 api。
- 允许计时器在Windows电源配置中将系统从睡眠状态唤醒。
from win32event import CreateWaitableTimer
from win32event import SetWaitableTimer
from win32event import WaitForSingleObject
import sys
def main(minutes):
minutes = int(minutes)
handle = CreateWaitableTimer(None, True, 'Wake up')
dt = -10000000 * minutes * 60 # Convert to seconds.
SetWaitableTimer(handle, dt, 0, None, None, True)
rc = WaitForSingleObject(handle, 1000 * (minutes + 1) * 60) # 11 s.
print ("Done")
if __name__ == '__main__':
minutes = sys.argv[1]
main(minutes)
要从控制台运行上述脚本,请调用wakeupWindows.py,例如:
For running the above script call wakeupWindows.py from console like:
python wakeupWindows.py 2
从现在开始将唤醒定时器设置为2分钟。
脚本将等待2 +1 = 3分钟。
从另一个控制台使用以下命令使系统进入睡眠状态:
Will set the wake up timer to 2 minutes from now. The script will wait for 2 + 1 = 3 minutes. From another console put the system off to sleep using:
shutdown /h
2分钟后,系统将从睡眠中唤醒。
After 2 minutes, the system will wake up from sleep.
类似的实现可以使用C#或使用pyinstaller将该脚本转换为exe,如这里。
Similar implementations are possible using C# or this script can be converted to an exe using pyinstaller as explained here.
这篇关于睡眠命令后唤醒Windows系统的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!