简体   繁体   English

如何使用 python 更改某个 windows 设置?

[英]How to change a certain windows setting using python?

I need to change this setting on/off using python:我需要使用 python 更改此设置的开/关:

'Automatically hide the taskbar in desktop mode' '在桌面模式下自动隐藏任务栏'

I have looked over the internet and can't find any ways to change the settings - this can be via python or command line.我查看了互联网,找不到任何更改设置的方法 - 这可以通过 python 或命令行。

What I'd really need is something like:我真正需要的是:

hideTaskbar = True # Hides taskbar
hideTaskbar = False # Shows taskbar
  1. You are able to do it with running a command that this link explains您可以通过运行此链接解释的命令来做到这一点

Hide隐藏

powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"

Show节目

powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=2;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
  1. You are able to run powersell command您可以运行 powersell 命令
import subprocess

showing = "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=2;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
hiding = "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
def run(cmd):
    subprocess.run(["powershell", "-Command", cmd])

run(hiding)

run(showing)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM