diff --git a/Scripts/Features/GetCurrentTweakState.ps1 b/Scripts/Features/GetCurrentTweakState.ps1 index 0d4e618..d0ec563 100644 --- a/Scripts/Features/GetCurrentTweakState.ps1 +++ b/Scripts/Features/GetCurrentTweakState.ps1 @@ -1,6 +1,22 @@ # Tests whether the registry operations in a feature's .reg file currently match the live registry. # Returns $true if ALL operations in the apply reg file match current system state. # Returns $false if the feature has no RegistryKey, the file is missing, or any operation mismatches. +function Get-ExpectedRegistryValueKind { + param( + [Parameter(Mandatory)] + $Operation + ) + + switch ([string]$Operation.ValueType) { + 'DWord' { return [Microsoft.Win32.RegistryValueKind]::DWord } + 'String' { return [Microsoft.Win32.RegistryValueKind]::String } + 'Binary' { return [Microsoft.Win32.RegistryValueKind]::Binary } + 'Hex2' { return [Microsoft.Win32.RegistryValueKind]::ExpandString } + 'Hex7' { return [Microsoft.Win32.RegistryValueKind]::MultiString } + default { return $null } + } +} + function Test-FeatureApplied { param ( [Parameter(Mandatory)] @@ -73,6 +89,8 @@ function Test-FeatureApplied { if (-not ($names -icontains $op.ValueName)) { return $false } $actualKind = $key.GetValueKind($op.ValueName) + $expectedKind = Get-ExpectedRegistryValueKind -Operation $op + if ($null -eq $expectedKind -or $actualKind -ne $expectedKind) { return $false } $actualRaw = $key.GetValue($op.ValueName, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) $actual = switch ($actualKind) { diff --git a/Scripts/Helpers/Get-RegFileOperations.ps1 b/Scripts/Helpers/Get-RegFileOperations.ps1 index 64eee4b..3cd22c2 100644 --- a/Scripts/Helpers/Get-RegFileOperations.ps1 +++ b/Scripts/Helpers/Get-RegFileOperations.ps1 @@ -131,7 +131,7 @@ function Convert-RegValueData { if ($valueData -match '^"(?.*)"$') { $stringValue = $matches.value # Unescape registry string escape sequences - $stringValue = $stringValue -replace '\\\\', '\' -replace '\"', '"' + $stringValue = $stringValue -replace '\\"', '"' -replace '\\\\', '\' return [PSCustomObject]@{ OperationType = 'SetValue' ValueType = 'String'