問題描述
如何使用 python 腳本使計算機進入睡眠狀態?
How can I make a computer sleep with a python script?
它必須是睡眠,而不是休眠或其他任何東西.
It has to be sleep, not hibernate or anything else.
我嘗試使用cmd
,但沒有睡眠命令或我沒有找到.
I have tried to use cmd
but there is no command to sleep or I didn't find one.
推薦答案
可以使用
import os
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
如果此命令對您不起作用(它實際上將您的計算機置于休眠模式),您將需要關閉休眠:
If this command doesn't work for you (it actually puts your comp. in hibernation mode) you will need to turn hibernation off:
Powercfg -H OFF
重新開啟休眠模式:
Powercfg -H ON
或者,您也可以使用:
Rundll32.exe Powrprof.dll,SetSuspendState Sleep
如果您不只想為了運行命令而關閉休眠,可以使用 psshutdown 作為替代
If you don't want to turn hibernation off just to run a command, you can use psshutdown as an alternative
C:WindowsSystem32psshutdown.exe -d -t 0
至于 os.system
的作用,直接來自 文檔:
As for what os.system
does, straight from the documentation:
在子shell中執行命令(字符串).
Execute the command (a string) in a subshell.
補充說明:
您需要擁有管理員權限才能運行 Powercfg -H *
You will need to have administrator permissions to run Powercfg -H *
這篇關于如何使用 python 腳本使 Windows 10 計算機進入睡眠狀態?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!