From f0afb6735a93f514b03700d8209890bcfab25b0f Mon Sep 17 00:00:00 2001 From: MyDrift Date: Tue, 5 Nov 2024 22:40:31 +0100 Subject: [PATCH 1/6] move logic to json template - remove Invoke-WPFToggle.ps1 - generalize Get-WinUtilToggleStatus - add bingsearch reg key for testing - use Invoke-WinUtilTweaks for actions - replace Add-Click with checked & unchecked to make undo work --- config/tweaks.json | 9 ++ functions/private/Get-WinUtilToggleStatus.ps1 | 88 +++++-------------- functions/private/Invoke-WinUtilTweaks.ps1 | 4 + functions/public/Invoke-WPFToggle.ps1 | 39 -------- functions/public/Invoke-WPFUIElements.ps1 | 11 ++- 5 files changed, 42 insertions(+), 109 deletions(-) delete mode 100644 functions/public/Invoke-WPFToggle.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index 93ed630c..27db404f 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3302,6 +3302,15 @@ "panel": "2", "Order": "a101_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Search", + "Name": "BingSearchEnabled", + "Value": "0", + "OriginalValue": "1", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/BingSearch" }, "WPFToggleNumLock": { diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 422d1d17..ea422c57 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -13,75 +13,29 @@ Function Get-WinUtilToggleStatus { #> Param($ToggleSwitch) - if($ToggleSwitch -eq "WPFToggleDarkMode") { - $app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme - $system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme - return $app -eq 0 -and $system -eq 0 - } - if($ToggleSwitch -eq "WPFToggleBingSearch") { - $bingsearch = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search').BingSearchEnabled - return $bingsearch -ne 0 - } - if($ToggleSwitch -eq "WPFToggleNumLock") { - $numlockvalue = (Get-ItemProperty -path 'HKCU:\Control Panel\Keyboard').InitialKeyboardIndicators - return $numlockvalue -eq 2 - } - if($ToggleSwitch -eq "WPFToggleVerboseLogon") { - $VerboseStatusvalue = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').VerboseStatus - return $VerboseStatusvalue -eq 1 - } - if($ToggleSwitch -eq "WPFToggleShowExt") { - $hideextvalue = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').HideFileExt - return $hideextvalue -eq 0 - } - if($ToggleSwitch -eq "WPFToggleSnapWindow") { - $hidesnap = (Get-ItemProperty -path 'HKCU:\Control Panel\Desktop').WindowArrangementActive - return $hidesnap -ne 0 - } - if($ToggleSwitch -eq "WPFToggleSnapFlyout") { - $hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').EnableSnapAssistFlyout - return $hidesnap -ne 0 - } - if($ToggleSwitch -eq "WPFToggleSnapSuggestion") { - $hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').SnapAssist - return $hidesnap -ne 0 - } - if($ToggleSwitch -eq "WPFToggleMouseAcceleration") { - $MouseSpeed = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseSpeed - $MouseThreshold1 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold1 - $MouseThreshold2 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold2 - return $MouseSpeed -eq 1 -and $MouseThreshold1 -eq 6 -and $MouseThreshold2 -eq 10 - } - if($ToggleSwitch -eq "WPFToggleTaskbarSearch") { - $SearchButton = (Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search").SearchboxTaskbarMode - return $SearchButton -ne 0 - } - if ($ToggleSwitch -eq "WPFToggleStickyKeys") { - $StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags - return $StickyKeys -ne 58 - } - if ($ToggleSwitch -eq "WPFToggleTaskView") { - $TaskView = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').ShowTaskViewButton - return $TaskView -ne 0 - } + $ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry - if ($ToggleSwitch -eq "WPFToggleHiddenFiles") { - $HiddenFiles = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').Hidden - return $HiddenFiles -ne 0 - } + if ($ToggleSwitchReg) { + $count = 0 - if ($ToggleSwitch -eq "WPFToggleTaskbarWidgets") { - $TaskbarWidgets = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskBarDa - return $TaskbarWidgets -ne 0 - } - if ($ToggleSwitch -eq "WPFToggleTaskbarAlignment") { - $TaskbarAlignment = (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskbarAl - return $TaskbarAlignment -ne 0 - } - if ($ToggleSwitch -eq "WPFToggleDetailedBSoD") { - $DetailedBSoD1 = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl').DisplayParameters - $DetailedBSoD2 = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl').DisableEmoticon - return !(($DetailedBSoD1 -eq 0) -or ($DetailedBSoD2 -eq 0) -or !$DetailedBSoD1 -or !$DetailedBSoD2) + foreach ($regentry in $ToggleSwitchReg) { + $regstate = (Get-ItemProperty -path $($regentry.Path)).$($regentry.Name) + if ($regstate -eq $regentry.Value) { + $count += 1 + } else { + write-debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" + } + } + + if ($count -eq $ToggleSwitchReg.Count) { + write-debug "$($ToggleSwitchReg.Name) is true (count: $count)" + return $true + } else { + write-debug "$($ToggleSwitchReg.Name) is false (count: $count)" + return $false + } + } else { + return $false } } diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index 8bb06faf..55577d54 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -21,6 +21,10 @@ function Invoke-WinUtilTweaks { $KeepServiceStartup = $true ) + if ($Checkbox -contains "Toggle") { + $CheckBox = $sync.configs.tweaks.$CheckBox + } + Write-Debug "Tweaks: $($CheckBox)" if($undo) { $Values = @{ diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 deleted file mode 100644 index c4fbd105..00000000 --- a/functions/public/Invoke-WPFToggle.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -function Invoke-WPFToggle { - - <# - - .SYNOPSIS - Invokes the scriptblock for the given toggle - - .PARAMETER Button - The name of the toggle to invoke - - #> - - Param ([string]$Button) - - # Use this to get the name of the button - #[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info") - - $ToggleStatus = (Get-WinUtilToggleStatus $Button) - - Switch -Wildcard ($Button) { - - "WPFToggleDarkMode" {Invoke-WinUtilDarkMode $ToggleStatus} - "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $ToggleStatus} - "WPFToggleNumLock" {Invoke-WinUtilNumLock $ToggleStatus} - "WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $ToggleStatus} - "WPFToggleShowExt" {Invoke-WinUtilShowExt $ToggleStatus} - "WPFToggleSnapWindow" {Invoke-WinUtilSnapWindow $ToggleStatus} - "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $ToggleStatus} - "WPFToggleSnapSuggestion" {Invoke-WinUtilSnapSuggestion $ToggleStatus} - "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $ToggleStatus} - "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $ToggleStatus} - "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $ToggleStatus} - "WPFToggleTaskbarSearch" {Invoke-WinUtilTaskbarSearch $ToggleStatus} - "WPFToggleTaskView" {Invoke-WinUtilTaskView $ToggleStatus} - "WPFToggleHiddenFiles" {Invoke-WinUtilHiddenFiles $ToggleStatus} - "WPFToggleTaskbarAlignment" {Invoke-WinUtilTaskbarAlignment $ToggleStatus} - "WPFToggleDetailedBSoD" {Invoke-WinUtilDetailedBSoD $ToggleStatus} - } -} diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index 3851536d..8ce21f88 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -192,11 +192,16 @@ function Invoke-WPFUIElements { $sync[$entryInfo.Name] = $checkBox - $sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $sync[$entryInfo.Name].Name + $sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $entryInfo.Name - $sync[$entryInfo.Name].Add_Click({ + $sync[$entryInfo.Name].Add_Checked({ [System.Object]$Sender = $args[0] - Invoke-WPFToggle $Sender.name + Invoke-WinUtilTweaks $sender.name + }) + + $sync[$entryInfo.Name].Add_Unchecked({ + [System.Object]$Sender = $args[0] + Invoke-WinUtiltweaks $sender.name -undo $true }) } From a93d44a6dc5ea5e630d6e5ef8bb6f45db3aca185 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Wed, 6 Nov 2024 01:09:09 +0100 Subject: [PATCH 2/6] add reg params for toggles into tweaks.json - add all reg keys to tweaks.json into existing toggle entry - remove unneeded scripts --- config/tweaks.json | 176 ++++++++++++++++++ .../private/Invoke-WinUtilBingSearch.ps1 | 30 --- functions/private/Invoke-WinUtilDarkMode.ps1 | 37 ---- .../private/Invoke-WinUtilDetailedBSoD.ps1 | 34 ---- .../private/Invoke-WinUtilHiddenFiles.ps1 | 30 --- .../Invoke-WinUtilMouseAcceleration.ps1 | 38 ---- functions/private/Invoke-WinUtilShowExt.ps1 | 27 --- .../private/Invoke-WinUtilSnapFlyout.ps1 | 30 --- .../private/Invoke-WinUtilSnapSuggestion.ps1 | 30 --- .../private/Invoke-WinUtilSnapWindow.ps1 | 27 --- .../private/Invoke-WinUtilStickyKeys.ps1 | 27 --- functions/private/Invoke-WinUtilTaskView.ps1 | 30 --- .../Invoke-WinUtilTaskbarAlignment.ps1 | 30 --- .../private/Invoke-WinUtilTaskbarSearch.ps1 | 30 --- .../private/Invoke-WinUtilTaskbarWidgets.ps1 | 30 --- .../private/Invoke-WinUtilVerboseLogon.ps1 | 27 --- 16 files changed, 176 insertions(+), 457 deletions(-) delete mode 100644 functions/private/Invoke-WinUtilBingSearch.ps1 delete mode 100644 functions/private/Invoke-WinUtilDarkMode.ps1 delete mode 100644 functions/private/Invoke-WinUtilDetailedBSoD.ps1 delete mode 100644 functions/private/Invoke-WinUtilHiddenFiles.ps1 delete mode 100644 functions/private/Invoke-WinUtilMouseAcceleration.ps1 delete mode 100644 functions/private/Invoke-WinUtilShowExt.ps1 delete mode 100644 functions/private/Invoke-WinUtilSnapFlyout.ps1 delete mode 100644 functions/private/Invoke-WinUtilSnapSuggestion.ps1 delete mode 100644 functions/private/Invoke-WinUtilSnapWindow.ps1 delete mode 100644 functions/private/Invoke-WinUtilStickyKeys.ps1 delete mode 100644 functions/private/Invoke-WinUtilTaskView.ps1 delete mode 100644 functions/private/Invoke-WinUtilTaskbarAlignment.ps1 delete mode 100644 functions/private/Invoke-WinUtilTaskbarSearch.ps1 delete mode 100644 functions/private/Invoke-WinUtilTaskbarWidgets.ps1 delete mode 100644 functions/private/Invoke-WinUtilVerboseLogon.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index 27db404f..4b2d47d1 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3293,6 +3293,28 @@ "panel": "2", "Order": "a100_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + "Name": "AppsUseLightTheme", + "Value": "0", + "OriginalValue": "1", + "Type": "DWord" + }, + { + "Path": "HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + "Name": "SystemUsesLightTheme", + "Value": "0", + "OriginalValue": "1", + "Type": "DWord" + } + ], + "InvokeScript": [ + "Invoke-WinUtilExplorerRefresh" + ], + "UndoScript": [ + "Invoke-WinUtilExplorerRefresh" + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/DarkMode" }, "WPFToggleBingSearch": { @@ -3320,6 +3342,22 @@ "panel": "2", "Order": "a102_", "Type": "Toggle", + "registry": [ + { + "Path": "HKU:\\.Default\\Control Panel\\Keyboard", + "Name": "InitialKeyboardIndicators", + "Value": "2", + "OriginalValue": "0", + "Type": "DWord" + }, + { + "Path": "HKCU:\\Control Panel\\Keyboard", + "Name": "InitialKeyboardIndicators", + "Value": "2", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/NumLock" }, "WPFToggleVerboseLogon": { @@ -3329,6 +3367,15 @@ "panel": "2", "Order": "a103_", "Type": "Toggle", + "registry": [ + { + "Path": "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", + "Name": "VerboseStatus", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/VerboseLogon" }, "WPFToggleSnapWindow": { @@ -3338,6 +3385,15 @@ "panel": "2", "Order": "a104_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Control Panel\\Desktop", + "Name": "WindowArrangementActive", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/SnapWindow" }, "WPFToggleSnapFlyout": { @@ -3347,6 +3403,15 @@ "panel": "2", "Order": "a105_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "EnableSnapAssistFlyout", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/SnapFlyout" }, "WPFToggleSnapSuggestion": { @@ -3356,6 +3421,15 @@ "panel": "2", "Order": "a106_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "SnapAssist", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/SnapSuggestion" }, "WPFToggleMouseAcceleration": { @@ -3365,6 +3439,29 @@ "panel": "2", "Order": "a107_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Control Panel\\Mouse", + "Name": "MouseSpeed", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + }, + { + "Path": "HKCU:\\Control Panel\\Mouse", + "Name": "MouseThreshold1", + "Value": "6", + "OriginalValue": "0", + "Type": "DWord" + }, + { + "Path": "HKCU:\\Control Panel\\Mouse", + "Name": "MouseThreshold2", + "Value": "10", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/MouseAcceleration" }, "WPFToggleStickyKeys": { @@ -3374,6 +3471,15 @@ "panel": "2", "Order": "a108_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Control Panel\\Accessibility\\StickyKeys", + "Name": "Flags", + "Value": "510", + "OriginalValue": "58", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/StickyKeys" }, "WPFToggleHiddenFiles": { @@ -3383,6 +3489,15 @@ "panel": "2", "Order": "a200_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "Hidden", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/HiddenFiles" }, "WPFToggleShowExt": { @@ -3392,6 +3507,15 @@ "panel": "2", "Order": "a201_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "HideFileExt", + "Value": "0", + "OriginalValue": "1", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/ShowExt" }, "WPFToggleTaskbarSearch": { @@ -3401,6 +3525,15 @@ "panel": "2", "Order": "a202_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Search", + "Name": "SearchboxTaskbarMode", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/TaskbarSearch" }, "WPFToggleTaskView": { @@ -3410,6 +3543,15 @@ "panel": "2", "Order": "a203_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "ShowTaskViewButton", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/TaskView" }, "WPFToggleTaskbarWidgets": { @@ -3419,6 +3561,15 @@ "panel": "2", "Order": "a204_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "TaskbarDa", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/TaskbarWidgets" }, "WPFToggleTaskbarAlignment": { @@ -3428,6 +3579,15 @@ "panel": "2", "Order": "a204_", "Type": "Toggle", + "registry": [ + { + "Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", + "Name": "TaskbarAl", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/TaskbarAlignment" }, "WPFToggleDetailedBSoD": { @@ -3437,6 +3597,22 @@ "panel": "2", "Order": "a205_", "Type": "Toggle", + "registry": [ + { + "Path": "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\CrashControl", + "Name": "DisplayParameters", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + }, + { + "Path": "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\CrashControl", + "Name": "DisableEmoticon", + "Value": "1", + "OriginalValue": "0", + "Type": "DWord" + } + ], "link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/DetailedBSoD" }, "WPFOOSUbutton": { diff --git a/functions/private/Invoke-WinUtilBingSearch.ps1 b/functions/private/Invoke-WinUtilBingSearch.ps1 deleted file mode 100644 index b7527bcb..00000000 --- a/functions/private/Invoke-WinUtilBingSearch.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilBingSearch { - <# - - .SYNOPSIS - Disables/Enables Bing Search - - .PARAMETER Enabled - Indicates whether to enable or disable Bing Search - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Bing Search" - $value = 1 - } else { - Write-Host "Disabling Bing Search" - $value = 0 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" - Set-ItemProperty -Path $Path -Name BingSearchEnabled -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-WinUtilDarkMode.ps1 b/functions/private/Invoke-WinUtilDarkMode.ps1 deleted file mode 100644 index 3fb1ecc5..00000000 --- a/functions/private/Invoke-WinUtilDarkMode.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -Function Invoke-WinUtilDarkMode { - <# - - .SYNOPSIS - Enables/Disables Dark Mode - - .PARAMETER DarkMoveEnabled - Indicates the current dark mode state - - #> - Param($DarkMoveEnabled) - try { - if ($DarkMoveEnabled -eq $false) { - Write-Host "Enabling Dark Mode" - $DarkMoveValue = 0 - } else { - Write-Host "Disabling Dark Mode" - $DarkMoveValue = 1 - } - - $Path = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" - Set-ItemProperty -Path $Path -Name AppsUseLightTheme -Value $DarkMoveValue - Set-ItemProperty -Path $Path -Name SystemUsesLightTheme -Value $DarkMoveValue - Invoke-WinUtilExplorerRefresh - # Update Winutil Theme if the Theme Button shows the Icon for Auto - if ($sync.ThemeButton.Content -eq [char]0xF08C) { - Invoke-WinutilThemeChange -theme "Auto" - } - } 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-WinUtilDetailedBSoD.ps1 b/functions/private/Invoke-WinUtilDetailedBSoD.ps1 deleted file mode 100644 index efe4f624..00000000 --- a/functions/private/Invoke-WinUtilDetailedBSoD.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -Function Invoke-WinUtilDetailedBSoD { - <# - - .SYNOPSIS - Enables/Disables Detailed BSoD - (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -Name 'DisplayParameters').DisplayParameters - - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Detailed BSoD" - $value = 1 - } else { - Write-Host "Disabling Detailed BSoD" - $value =0 - } - - $Path = "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" - $dwords = ("DisplayParameters", "DisableEmoticon") - foreach ($name in $dwords) { - Set-ItemProperty -Path $Path -Name $name -Value $value - } - Set-ItemProperty -Path $Path -Name DisplayParameters -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-WinUtilHiddenFiles.ps1 b/functions/private/Invoke-WinUtilHiddenFiles.ps1 deleted file mode 100644 index 5309d2c3..00000000 --- a/functions/private/Invoke-WinUtilHiddenFiles.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilHiddenFiles { - <# - - .SYNOPSIS - Enable/Disable Hidden Files - - .PARAMETER Enabled - Indicates whether to enable or disable Hidden Files - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Hidden Files" - $value = 1 - } else { - Write-Host "Disabling Hidden Files" - $value = 0 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - Set-ItemProperty -Path $Path -Name Hidden -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-WinUtilMouseAcceleration.ps1 b/functions/private/Invoke-WinUtilMouseAcceleration.ps1 deleted file mode 100644 index f29bdeee..00000000 --- a/functions/private/Invoke-WinUtilMouseAcceleration.ps1 +++ /dev/null @@ -1,38 +0,0 @@ -Function Invoke-WinUtilMouseAcceleration { - <# - - .SYNOPSIS - Enables/Disables Mouse Acceleration - - .PARAMETER DarkMoveEnabled - Indicates the current Mouse Acceleration State - - #> - Param($MouseAccelerationEnabled) - try { - if ($MouseAccelerationEnabled -eq $false) { - Write-Host "Enabling Mouse Acceleration" - $MouseSpeed = 1 - $MouseThreshold1 = 6 - $MouseThreshold2 = 10 - } else { - Write-Host "Disabling Mouse Acceleration" - $MouseSpeed = 0 - $MouseThreshold1 = 0 - $MouseThreshold2 = 0 - - } - - $Path = "HKCU:\Control Panel\Mouse" - Set-ItemProperty -Path $Path -Name MouseSpeed -Value $MouseSpeed - Set-ItemProperty -Path $Path -Name MouseThreshold1 -Value $MouseThreshold1 - Set-ItemProperty -Path $Path -Name MouseThreshold2 -Value $MouseThreshold2 - } 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-WinUtilShowExt.ps1 b/functions/private/Invoke-WinUtilShowExt.ps1 deleted file mode 100644 index c90265a8..00000000 --- a/functions/private/Invoke-WinUtilShowExt.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -function Invoke-WinUtilShowExt { - <# - .SYNOPSIS - Disables/Enables Show file Extentions - .PARAMETER Enabled - Indicates whether to enable or disable Show file extentions - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Showing file extentions" - $value = 0 - } else { - Write-Host "hiding file extensions" - $value = 1 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - Set-ItemProperty -Path $Path -Name HideFileExt -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-WinUtilSnapFlyout.ps1 b/functions/private/Invoke-WinUtilSnapFlyout.ps1 deleted file mode 100644 index 39d1335b..00000000 --- a/functions/private/Invoke-WinUtilSnapFlyout.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilSnapFlyout { - <# - .SYNOPSIS - Disables/Enables Snap Assist Flyout on startup - .PARAMETER Enabled - Indicates whether to enable or disable Snap Assist Flyout on startup - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Snap Assist Flyout On startup" - $value = 1 - } else { - Write-Host "Disabling Snap Assist Flyout On startup" - $value = 0 - } - - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - taskkill.exe /F /IM "explorer.exe" - Set-ItemProperty -Path $Path -Name EnableSnapAssistFlyout -Value $value - Start-Process "explorer.exe" - } 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-WinUtilSnapSuggestion.ps1 b/functions/private/Invoke-WinUtilSnapSuggestion.ps1 deleted file mode 100644 index f2358c73..00000000 --- a/functions/private/Invoke-WinUtilSnapSuggestion.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilSnapSuggestion { - <# - .SYNOPSIS - Disables/Enables Snap Assist Suggestions on startup - .PARAMETER Enabled - Indicates whether to enable or disable Snap Assist Suggestions on startup - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Snap Assist Suggestion On startup" - $value = 1 - } else { - Write-Host "Disabling Snap Assist Suggestion On startup" - $value = 0 - } - # taskkill.exe /F /IM "explorer.exe" - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - taskkill.exe /F /IM "explorer.exe" - Set-ItemProperty -Path $Path -Name SnapAssist -Value $value - Start-Process "explorer.exe" - } 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-WinUtilSnapWindow.ps1 b/functions/private/Invoke-WinUtilSnapWindow.ps1 deleted file mode 100644 index c76e1c7d..00000000 --- a/functions/private/Invoke-WinUtilSnapWindow.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -function Invoke-WinUtilSnapWindow { - <# - .SYNOPSIS - Disables/Enables Snapping Windows on startup - .PARAMETER Enabled - Indicates whether to enable or disable Snapping Windows on startup - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Snap Windows On startup | Relogin Required" - $value = 1 - } else { - Write-Host "Disabling Snap Windows On startup | Relogin Required" - $value = 0 - } - $Path = "HKCU:\Control Panel\Desktop" - Set-ItemProperty -Path $Path -Name WindowArrangementActive -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-WinUtilStickyKeys.ps1 b/functions/private/Invoke-WinUtilStickyKeys.ps1 deleted file mode 100644 index b7d8860f..00000000 --- a/functions/private/Invoke-WinUtilStickyKeys.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -Function Invoke-WinUtilStickyKeys { - <# - .SYNOPSIS - Disables/Enables Sticky Keyss on startup - .PARAMETER Enabled - Indicates whether to enable or disable Sticky Keys on startup - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Sticky Keys On startup" - $value = 510 - } else { - Write-Host "Disabling Sticky Keys On startup" - $value = 58 - } - $Path = "HKCU:\Control Panel\Accessibility\StickyKeys" - Set-ItemProperty -Path $Path -Name Flags -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-WinUtilTaskView.ps1 b/functions/private/Invoke-WinUtilTaskView.ps1 deleted file mode 100644 index 3af1beb6..00000000 --- a/functions/private/Invoke-WinUtilTaskView.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilTaskView { - <# - - .SYNOPSIS - Enable/Disable Task View - - .PARAMETER Enabled - Indicates whether to enable or disable Task View - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Task View" - $value = 1 - } else { - Write-Host "Disabling Task View" - $value = 0 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - Set-ItemProperty -Path $Path -Name ShowTaskViewButton -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-WinUtilTaskbarAlignment.ps1 b/functions/private/Invoke-WinUtilTaskbarAlignment.ps1 deleted file mode 100644 index e3f512f7..00000000 --- a/functions/private/Invoke-WinUtilTaskbarAlignment.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilTaskbarAlignment { - <# - - .SYNOPSIS - Switches between Center & Left Taskbar Alignment - - .PARAMETER Enabled - Indicates whether to make Taskbar Alignment Center or Left - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Making Taskbar Alignment to the Center" - $value = 1 - } else { - Write-Host "Making Taskbar Alignment to the Left" - $value = 0 - } - $Path = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - Set-ItemProperty -Path $Path -Name "TaskbarAl" -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-WinUtilTaskbarSearch.ps1 b/functions/private/Invoke-WinUtilTaskbarSearch.ps1 deleted file mode 100644 index b35d4816..00000000 --- a/functions/private/Invoke-WinUtilTaskbarSearch.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilTaskbarSearch { - <# - - .SYNOPSIS - Enable/Disable Taskbar Search Button. - - .PARAMETER Enabled - Indicates whether to enable or disable Taskbar Search Button. - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Search Button" - $value = 1 - } else { - Write-Host "Disabling Search Button" - $value = 0 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\" - Set-ItemProperty -Path $Path -Name SearchboxTaskbarMode -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-WinUtilTaskbarWidgets.ps1 b/functions/private/Invoke-WinUtilTaskbarWidgets.ps1 deleted file mode 100644 index f8b2ce3a..00000000 --- a/functions/private/Invoke-WinUtilTaskbarWidgets.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Invoke-WinUtilTaskbarWidgets { - <# - - .SYNOPSIS - Enable/Disable Taskbar Widgets - - .PARAMETER Enabled - Indicates whether to enable or disable Taskbar Widgets - - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Taskbar Widgets" - $value = 1 - } else { - Write-Host "Disabling Taskbar Widgets" - $value = 0 - } - $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - Set-ItemProperty -Path $Path -Name TaskbarDa -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-WinUtilVerboseLogon.ps1 b/functions/private/Invoke-WinUtilVerboseLogon.ps1 deleted file mode 100644 index 9bed241c..00000000 --- a/functions/private/Invoke-WinUtilVerboseLogon.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -function Invoke-WinUtilVerboseLogon { - <# - .SYNOPSIS - Disables/Enables VerboseLogon Messages - .PARAMETER Enabled - Indicates whether to enable or disable VerboseLogon messages - #> - Param($Enabled) - try { - if ($Enabled -eq $false) { - Write-Host "Enabling Verbose Logon Messages" - $value = 1 - } else { - Write-Host "Disabling Verbose Logon Messages" - $value = 0 - } - $Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" - Set-ItemProperty -Path $Path -Name VerboseStatus -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 - } -} From 5c2d5fae1e34a29e05933214e49220834d4920b2 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Wed, 6 Nov 2024 19:13:32 +0100 Subject: [PATCH 3/6] 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) } } From a4fccd3c85526ad5415eb3731f6f18bc6e31319a Mon Sep 17 00:00:00 2001 From: MyDrift Date: Wed, 6 Nov 2024 22:16:01 +0100 Subject: [PATCH 4/6] add a lot of error handling --- functions/private/Get-WinUtilToggleStatus.ps1 | 15 +++++++++++---- functions/private/Invoke-WinUtilTweaks.ps1 | 7 ++++++- functions/public/Invoke-WPFUIElements.ps1 | 8 +++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index b30aea94..0ac3f208 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -19,25 +19,32 @@ Function Get-WinUtilToggleStatus { 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 (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { + Write-Host "HKU drive created successfully" -ForegroundColor Green + } else { + Write-Host "Failed to create HKU drive" + } } if ($ToggleSwitchReg) { $count = 0 foreach ($regentry in $ToggleSwitchReg) { - $regstate = (Get-ItemProperty -path $($regentry.Path)).$($regentry.Name) + write-host "Checking $($regentry.path)" + $regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name) if ($regstate -eq $regentry.Value) { $count += 1 + write-host "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" -ForegroundColor Green } else { - write-debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" + write-host "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" } } if ($count -eq $ToggleSwitchReg.Count) { - write-debug "$($ToggleSwitchReg.Name) is true (count: $count)" + write-host "$($ToggleSwitchReg.Name) is true (count: $count)" -ForegroundColor Green return $true } else { - write-debug "$($ToggleSwitchReg.Name) is false (count: $count)" + write-host "$($ToggleSwitchReg.Name) is false (count: $count)" return $false } } else { diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index f5bedfcf..d64f4cd9 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -77,9 +77,14 @@ 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)) { + 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 (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { + Write-Host "HKU drive created successfully" + } else { + Write-Host "Failed to create HKU drive" + } } Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) } diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index 8ce21f88..90fb8760 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -192,7 +192,13 @@ function Invoke-WPFUIElements { $sync[$entryInfo.Name] = $checkBox - $sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $entryInfo.Name + $sync[$entryInfo.Name].IsChecked = (Get-WinUtilToggleStatus $entryInfo.Name) + + if ($sync[$entryInfo.Name].IsChecked) { + write-host "$($entryInfo.Name) is checked" -ForegroundColor Blue + } else { + write-host "$($entryInfo.Name) is not checked" -ForegroundColor Red + } $sync[$entryInfo.Name].Add_Checked({ [System.Object]$Sender = $args[0] From feff1078d8beb3959e866c108529dab8e5e4d4e1 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:58:41 +0100 Subject: [PATCH 5/6] Bugfix: New-PSDrive seems to return the "hku" itself so weirdly gets prepended to the return value so the result becomes ("hku", $false). In powershell pretty much every variable that exists is interpreted as $true so the toggle for numlock got incorrectly checked --- functions/private/Get-WinUtilToggleStatus.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 0ac3f208..58a31dee 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -17,7 +17,7 @@ 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 + $null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS write-host "Created HKU drive" if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { Write-Host "HKU drive created successfully" -ForegroundColor Green From 667d96c3979d494e674adf91db549dd80381858c Mon Sep 17 00:00:00 2001 From: MyDrift Date: Thu, 7 Nov 2024 08:25:30 +0100 Subject: [PATCH 6/6] globally fix HKU error & minimize console feedback - fix HKU issue globally - remove some console logs, change some others to write-debug --- functions/private/Get-WinUtilToggleStatus.ps1 | 16 +++++++--------- .../private/Invoke-WinUtilCurrentSystem.ps1 | 2 +- functions/private/Invoke-WinUtilTweaks.ps1 | 9 ++++----- functions/public/Invoke-WPFUIElements.ps1 | 6 ------ 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 58a31dee..da222472 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -17,12 +17,11 @@ Function Get-WinUtilToggleStatus { $ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { - $null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS - write-host "Created HKU drive" + $null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS) if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { - Write-Host "HKU drive created successfully" -ForegroundColor Green + Write-Debug "HKU drive created successfully" } else { - Write-Host "Failed to create HKU drive" + Write-Debug "Failed to create HKU drive" } } @@ -30,21 +29,20 @@ Function Get-WinUtilToggleStatus { $count = 0 foreach ($regentry in $ToggleSwitchReg) { - write-host "Checking $($regentry.path)" $regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name) if ($regstate -eq $regentry.Value) { $count += 1 - write-host "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" -ForegroundColor Green + Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" } else { - write-host "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" + Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" } } if ($count -eq $ToggleSwitchReg.Count) { - write-host "$($ToggleSwitchReg.Name) is true (count: $count)" -ForegroundColor Green + Write-Debug "$($ToggleSwitchReg.Name) is true (count: $count)" return $true } else { - write-host "$($ToggleSwitchReg.Name) is false (count: $count)" + Write-Debug "$($ToggleSwitchReg.Name) is false (count: $count)" return $false } } else { diff --git a/functions/private/Invoke-WinUtilCurrentSystem.ps1 b/functions/private/Invoke-WinUtilCurrentSystem.ps1 index e62568f4..82d7938f 100644 --- a/functions/private/Invoke-WinUtilCurrentSystem.ps1 +++ b/functions/private/Invoke-WinUtilCurrentSystem.ps1 @@ -43,7 +43,7 @@ Function Invoke-WinUtilCurrentSystem { if($CheckBox -eq "tweaks") { - if(!(Test-Path 'HKU:\')) {New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS} + if(!(Test-Path 'HKU:\')) {$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)} $ScheduledTasks = Get-ScheduledTask $sync.configs.tweaks | Get-Member -MemberType NoteProperty | ForEach-Object { diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index d64f4cd9..a6822111 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -77,13 +77,12 @@ 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 (($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 (($psitem.Path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { + $null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS) if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { - Write-Host "HKU drive created successfully" + Write-Debug "HKU drive created successfully" } else { - Write-Host "Failed to create HKU drive" + Write-Debug "Failed to create HKU drive" } } Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index 90fb8760..7ae64d3d 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -194,12 +194,6 @@ function Invoke-WPFUIElements { $sync[$entryInfo.Name].IsChecked = (Get-WinUtilToggleStatus $entryInfo.Name) - if ($sync[$entryInfo.Name].IsChecked) { - write-host "$($entryInfo.Name) is checked" -ForegroundColor Blue - } else { - write-host "$($entryInfo.Name) is not checked" -ForegroundColor Red - } - $sync[$entryInfo.Name].Add_Checked({ [System.Object]$Sender = $args[0] Invoke-WinUtilTweaks $sender.name