improve handling if entry does not exist

- add DefaultState property
- add handler for DefaultState in Get-WinUtilToggleStatus
This commit is contained in:
MyDrift 2024-12-09 06:36:30 +01:00
parent 6b1a914e9e
commit a2c31008cf
2 changed files with 41 additions and 1 deletions

View File

@ -3349,6 +3349,7 @@
"Name": "BingSearchEnabled", "Name": "BingSearchEnabled",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3392,6 +3393,7 @@
"Name": "VerboseStatus", "Name": "VerboseStatus",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3410,6 +3412,7 @@
"Name": "HideRecommendedSection", "Name": "HideRecommendedSection",
"Value": "0", "Value": "0",
"OriginalValue": "1", "OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
}, },
{ {
@ -3417,6 +3420,7 @@
"Name": "IsEducationEnvironment", "Name": "IsEducationEnvironment",
"Value": "0", "Value": "0",
"OriginalValue": "1", "OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
}, },
{ {
@ -3424,6 +3428,7 @@
"Name": "HideRecommendedSection", "Name": "HideRecommendedSection",
"Value": "0", "Value": "0",
"OriginalValue": "1", "OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3442,6 +3447,7 @@
"Name": "WindowArrangementActive", "Name": "WindowArrangementActive",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "String" "Type": "String"
} }
], ],
@ -3460,6 +3466,7 @@
"Name": "EnableSnapAssistFlyout", "Name": "EnableSnapAssistFlyout",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3488,6 +3495,7 @@
"Name": "SnapAssist", "Name": "SnapAssist",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3516,6 +3524,7 @@
"Name": "MouseSpeed", "Name": "MouseSpeed",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
}, },
{ {
@ -3523,6 +3532,7 @@
"Name": "MouseThreshold1", "Name": "MouseThreshold1",
"Value": "6", "Value": "6",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
}, },
{ {
@ -3530,6 +3540,7 @@
"Name": "MouseThreshold2", "Name": "MouseThreshold2",
"Value": "10", "Value": "10",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3548,6 +3559,7 @@
"Name": "Flags", "Name": "Flags",
"Value": "510", "Value": "510",
"OriginalValue": "58", "OriginalValue": "58",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3622,6 +3634,7 @@
"Name": "SearchboxTaskbarMode", "Name": "SearchboxTaskbarMode",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3640,6 +3653,7 @@
"Name": "ShowTaskViewButton", "Name": "ShowTaskViewButton",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3658,6 +3672,7 @@
"Name": "TaskbarDa", "Name": "TaskbarDa",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3676,6 +3691,7 @@
"Name": "TaskbarAl", "Name": "TaskbarAl",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord" "Type": "DWord"
} }
], ],
@ -3694,6 +3710,7 @@
"Name": "DisplayParameters", "Name": "DisplayParameters",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord" "Type": "DWord"
}, },
{ {
@ -3701,6 +3718,7 @@
"Name": "DisableEmoticon", "Name": "DisableEmoticon",
"Value": "1", "Value": "1",
"OriginalValue": "0", "OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord" "Type": "DWord"
} }
], ],

View File

@ -35,6 +35,9 @@ Function Get-WinUtilToggleStatus {
foreach ($regentry in $ToggleSwitchReg) { foreach ($regentry in $ToggleSwitchReg) {
try { try {
if (!(Test-Path $regentry.Path)) {
New-Item -Path $regentry.Path -Force | Out-Null
}
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name) $regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
if ($regstate -eq $regentry.Value) { if ($regstate -eq $regentry.Value) {
$count += 1 $count += 1
@ -42,8 +45,27 @@ Function Get-WinUtilToggleStatus {
} else { } else {
Write-Debug "$($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 (!$regstate) {
write-host "missing $($regentry.Name)"
switch ($regentry.DefaultState) {
"true" {
write-host "true"
$regstate = $regentry.Value
$count += 1
}
"false" {
write-host "false"
$regstate = $regentry.OriginalValue
}
default {
write-host "default"
Write-Error "Entry for $($regentry.Name) does not exist and no DefaultState is defined."
$regstate = $regentry.OriginalValue
}
}
}
} catch { } catch {
Write-Error "An error occurred while accessing registry entry $($regentry.Path): $_" Write-Error "An unexpected error occurred: $_"
} }
} }