Powershell을 사용하여 변수에 대한 레지스트리 값을 가져오는 방법은 무엇입니까? (Windows 10에서 다크 모드를 전환하는 프로그래밍 방식 구현)

Powershell을 사용하여 변수에 대한 레지스트리 값을 가져오는 방법은 무엇입니까? (Windows 10에서 다크 모드를 전환하는 프로그래밍 방식 구현)

Windows 10용 다크 모드 전환기를 구현하고 있습니다.저것다음을 통해 다크 모드를 활성화할 수 있습니다.

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

그리고 조명 모드를 통해

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

이제 토글을 구현하고 싶습니다. 난 노력 했어

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

0 또는 1을 얻는 대신 다음과 같은 출력을 얻었습니다.

AppsUseLightTheme : 1
PSPath            : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize
PSParentPath      : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes
PSChildName       : Personalize
PSDrive           : HKCU
PSProvider        : Microsoft.PowerShell.Core\Registry

1실제로 변수에 저장하고 전환하려면 어떻게 해야 합니까 ?

답변1

좋습니다. 실제로는 간단했습니다. 점 표기법을 사용하여 필드 값을 가져와야 했습니다.

$mode = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme).AppsUseLightTheme
$newMode = 1 - $mode
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value $newMode -Type Dword -Force

Win다음은 다크 모드를 + 로 전환하는 AutoHotKey 스크립트입니다 Q.

; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Yakov Litvin
; Source:         https://superuser.com/a/1724237/576393
;
; Script Function:
;   toggle Windows dark mode on Win + Q
;
; based on https://stackoverflow.com/a/35844524/3995261

psScript =
(
  $mode = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme).AppsUseLightTheme
  $newMode = 1 - $mode
  Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value $newMode -Type Dword -Force
)

#vk51::Run, PowerShell.exe -Command &{%psScript%},, hide

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

관련 정보