使用 Python 编辑 Windows 8 电源选项 [英] Use Python to Edit Windows 8 Power Options

查看:21
本文介绍了使用 Python 编辑 Windows 8 电源选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
每次我重新启动计算机时,我的 Windows 8 电源设置都会恢复为默认设置,并在一个小时后让我的计算机进入睡眠状态.我不希望我的计算机进入睡眠状态,除非我这么说......我必须进入控制面板 > 系统和安全 > 电源选项 > 编辑计划设置,然后手动将计算机进入睡眠状态设置为从不.

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.


我想要什么:
用于在 Windows 8 中编辑电源选项的 Python 脚本.我会将其设置为每次重新启动时运行.


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

我搜索了一个 Python 模块来编辑 Windows 设置,但找不到我要找的内容.不久前,我曾使用 win32api 来控制我的课程,但在其文档中找不到电源选项.

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 关于使用 powercfg 命令行选项的提示非常完美.这是我最终使用的简单脚本:


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")

-standby-timeout-ac 选项设置为零,这样我的电脑就永远不会进入睡眠状态

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

推荐答案

我认为你应该看看 powercfg Windows 的命令并使用 python 的 subprocess.call 设置您喜欢的任何内容,例如:

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")

我想这是不言自明的:将-ac"更改为-dc"以进行电池设置,值以分钟为单位,零显然代表无穷大.

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

这篇关于使用 Python 编辑 Windows 8 电源选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆