在 Windows 的深色和浅色模式之间即时切换

问题描述 投票:0回答:3

如何以编程方式在 Windows 的深色模式和浅色模式之间切换。 我使用了注册表项,

HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\SystemUsesLightTheme

但它并不像“颜色设置\个性化\颜色”窗口中的切换开关那样直接执行命令。

Windows 不会立即响应通过注册表项更改深色或浅色模式

windows themes darkmode lightmode
3个回答
2
投票

您可以使用 PowerShell 脚本来实现这一点。示例:

在应用程序上启用深色模式

New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force

在应用程序上启用灯光模式

Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme

0
投票

您可以在 Windows 任务计划程序中为您想要的每种模式(例如,浅色和深色)触发事件。 在“操作”选项卡中,在程序或脚本中使用 Powershell 设置“启动程序”(键入以下行):

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

在“添加可选参数”中,插入此行(根据一天中的时间,将

AppsUseLightTheme
更改为您想要设置的 var 和值 0/1):

Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1

此外,为了回答 @Bender110001 答案中的一些评论,您在 Win11 中获得了 2 个用于自定义主题的变量(也可能是 10 个):

  • AppsUseLightTheme
    用于应用程序(Pycharm、浏览器页面等)
  • SystemUseLightTheme
    用于系统颜色(正如您在 Win 自定义手动配置中看到的那样:任务栏、窗口、应用程序外的操作系统样式)。

0
投票

基于本德的回答。我创建了一个文件,可以在浅色和深色主题之间切换。

  1. 创建

    toggleWinTheme.ps1.

  2. 粘贴下面的代码并保存

  3. 然后右键单击该文件并选择

    Run with PowerShell

# Get the current mode
$currentMode = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme

# Toggle the mode
if ($currentMode -eq 1) {
    # If currently in Light Mode, switch to Dark Mode
    Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0
    Write-Output "Switched to Dark Mode"
} else {
    # If currently in Dark Mode, switch to Light Mode
    Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1
    Write-Output "Switched to Light Mode"
}

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.