From 5c2d5fae1e34a29e05933214e49220834d4920b2 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Wed, 6 Nov 2024 19:13:32 +0100 Subject: [PATCH] fix HKU - load HKU if needed (for tweaks & GetToggleStatus) - remove unneeded Invoke-WinUtilNumLock - has loaded HKU does not load/not stay loaded --- config/tweaks.json | 8 +++-- functions/private/Get-WinUtilToggleStatus.ps1 | 5 +++ functions/private/Invoke-WinUtilNumLock.ps1 | 31 ------------------- functions/private/Invoke-WinUtilTweaks.ps1 | 4 +++ 4 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 functions/private/Invoke-WinUtilNumLock.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index 4b2d47d1..200e39d8 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3310,10 +3310,14 @@ } ], "InvokeScript": [ - "Invoke-WinUtilExplorerRefresh" + " + Invoke-WinUtilExplorerRefresh + " ], "UndoScript": [ - "Invoke-WinUtilExplorerRefresh" + " + Invoke-WinUtilExplorerRefresh + " ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/DarkMode" }, diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index ea422c57..b30aea94 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -16,6 +16,11 @@ Function Get-WinUtilToggleStatus { $ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry + if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { + New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS + write-host "Created HKU drive" + } + if ($ToggleSwitchReg) { $count = 0 diff --git a/functions/private/Invoke-WinUtilNumLock.ps1 b/functions/private/Invoke-WinUtilNumLock.ps1 deleted file mode 100644 index fd7eb969..00000000 --- a/functions/private/Invoke-WinUtilNumLock.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -function Invoke-WinUtilNumLock { - <# - .SYNOPSIS - Disables/Enables NumLock on startup - .PARAMETER Enabled - Indicates whether to enable or disable Numlock on startup - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Numlock on startup" - $value = 2 - } else { - Write-Host "Disabling Numlock on startup" - $value = 0 - } - New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS - $HKUPath = "HKU:\.Default\Control Panel\Keyboard" - $HKCUPath = "HKCU:\Control Panel\Keyboard" - Set-ItemProperty -Path $HKUPath -Name InitialKeyboardIndicators -Value $value - Set-ItemProperty -Path $HKCUPath -Name InitialKeyboardIndicators -Value $value - } - Catch [System.Security.SecurityException] { - Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" - } catch [System.Management.Automation.ItemNotFoundException] { - Write-Warning $psitem.Exception.ErrorRecord - } catch { - Write-Warning "Unable to set $Name due to unhandled exception" - Write-Warning $psitem.Exception.StackTrace - } -} diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index 55577d54..f5bedfcf 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -77,6 +77,10 @@ function Invoke-WinUtilTweaks { if($sync.configs.tweaks.$CheckBox.registry) { $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))" + if (($psitem.Path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { + New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS + write-host "Created HKU drive" + } Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) } }