Use Python to Edit Windows 8 Power Options

别来无恙 提交于 2019-12-10 20:57:46

问题


The Problem:
Every time I restart my computer my Windows 8 power settings go back to default and puts my computer to sleep after an hour. I don't want my computer to ever go to sleep unless I say so... I have to go in Control Panel > System and Security > Power Options > Edit Plan Settings and manually edit the put the computer to sleep setting to Never.


What I want:
A Python script to edit the Power Options in Windows 8. I will set it to run every time I reboot.

I've searched for a Python module to edit Windows settings but couldn't find what I was looking for. I've played with win32api to control my courser a while back but couldn't find Power Options in its documentation.


Julius Caesar's hint about using powercfg command-line options was perfect. Here is the simple script I ended up using:
import subprocess
subprocess.call("powercfg -change -standby-timeout-ac 0")

The -standby-timeout-ac option is set to zero so my computer will Never go to sleep


回答1:


I think You should look into powercfg Windows' command and set whatever You like with python's subprocess.call, for example:

import subprocess
subprocess.call("powercfg -change -monitor-timeout-ac 666")

I guess it is pretty self-explanatory: change '-ac' to '-dc' for battery setting, value is in minutes and zero stands for infinity, obviously.



来源:https://stackoverflow.com/questions/25653576/use-python-to-edit-windows-8-power-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!