DeepSeek 写的一些电脑常规设置

    1

主要功能:

关闭锁屏

关闭屏幕保护程序

关闭防火墙

设置屏幕缩放与布局为100%

显示器、休眠时间修改为从不

python 代码展示

import os
import subprocess
import platform
import sys
import io
import winreg  # 用于操作注册表

# 设置标准输出编码为UTF-8
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

def get_system_info():
    print("=== 系统信息 ===")
    print(f"操作系统: {platform.system()} {platform.release()}")
    print(f"系统版本: {platform.version()}")
    print(f"计算机名称: {platform.node()}")
    print(f"处理器: {platform.processor()}")
    print(f"系统架构: {platform.machine()}\n")

def disable_lock_screen():
    print("=== 关闭锁屏 ===")
    try:
        subprocess.run(["powercfg", "/SETACVALUEINDEX", "SCHEME_CURRENT", "SUB_NONE", "CONSOLELOCK", "0"], check=True)
        print("锁屏已关闭。\n")
    except subprocess.CalledProcessError as e:
        print(f"关闭锁屏时出错: {e}\n")

def disable_screen_saver():
    print("=== 关闭屏幕保护程序 ===")
    try:
        subprocess.run(["reg", "add", "HKCU\\Control Panel\\Desktop", "/v", "ScreenSaveActive", "/t", "REG_SZ", "/d", "0", "/f"], check=True)
        print("屏幕保护程序已关闭。\n")
    except subprocess.CalledProcessError as e:
        print(f"关闭屏幕保护程序时出错: {e}\n")

def disable_firewall():
    print("=== 关闭防火墙 ===")
    try:
        subprocess.run(["netsh", "advfirewall", "set", "allprofiles", "state", "off"], check=True)
        print("防火墙已关闭。\n")
    except subprocess.CalledProcessError as e:
        print(f"关闭防火墙时出错: {e}\n")

def set_display_and_sleep_never():
    print("=== 设置显示器关闭和休眠时间为从不 ===")
    try:
        subprocess.run(["powercfg", "/change", "monitor-timeout-ac", "0"], check=True)
        subprocess.run(["powercfg", "/change", "standby-timeout-ac", "0"], check=True)
        print("显示器关闭和休眠时间已设置为从不。\n")
    except subprocess.CalledProcessError as e:
        print(f"设置显示器关闭和休眠时间时出错: {e}\n")

def set_scaling_to_100():
    print("=== 设置缩放与布局为 100% ===")
    try:
        # 打开注册表键
        reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Control Panel\Desktop", 0, winreg.KEY_WRITE)
        # 设置缩放比例为 100%
        winreg.SetValueEx(reg_key, "LogPixels", 0, winreg.REG_DWORD, 96)  # 96 是 100% 缩放的值
        winreg.CloseKey(reg_key)
        print("缩放与布局已设置为 100%。\n")
    except Exception as e:
        print(f"设置缩放与布局时出错: {e}\n")

def main():
    get_system_info()
    disable_lock_screen()
    disable_screen_saver()
    disable_firewall()
    set_display_and_sleep_never()
    set_scaling_to_100()  # 新增功能:设置缩放与布局为 100%
    input("操作已完成,按回车键退出...")  # 保留窗口

if __name__ == "__main__":
    main()

注意事项:

  • 管理员权限:修改注册表和系统设置需要管理员权限,请确保以管理员身份运行脚本。

  • 重启生效:修改缩放设置后,可能需要注销或重启系统才能生效。

  • 备份注册表:在修改注册表之前,建议备份注册表,以防出现问题。


示例输出

=== 系统信息 ===
操作系统: Windows 10
系统版本: 10.0.19041
计算机名称: DESKTOP-ABC123
处理器: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
系统架构: AMD64

=== 关闭锁屏 ===
锁屏已关闭。

=== 关闭屏幕保护程序 ===
屏幕保护程序已关闭。

=== 关闭防火墙 ===
防火墙已关闭。

=== 设置显示器关闭和休眠时间为从不 ===
显示器关闭和休眠时间已设置为从不。

=== 设置缩放与布局为 100% ===
缩放与布局已设置为 100%。

操作已完成,按回车键退出...

消息盒子

# 暂无消息 #

只显示最新10条未读和已读信息