From 4ff12ab54330978b7386033c5d03440a437465df Mon Sep 17 00:00:00 2001 From: sysadmin Date: Tue, 9 Jun 2026 14:23:50 +0100 Subject: [PATCH] fix(branding): guard reg unload, set ErrorAction in libs, accent field rename, test hive unload + assertions --- windows/branding/Apply-Branding.ps1 | 6 +++++- windows/branding/branding.manifest.json | 2 +- windows/branding/lib/BrandingLayers.ps1 | 5 +++-- windows/branding/lib/RegistryHelpers.ps1 | 1 + windows/tests/Branding.Tests.ps1 | 3 +++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/windows/branding/Apply-Branding.ps1 b/windows/branding/Apply-Branding.ps1 index ca91545..c196a2b 100644 --- a/windows/branding/Apply-Branding.ps1 +++ b/windows/branding/Apply-Branding.ps1 @@ -47,7 +47,11 @@ function Invoke-WithHive { & reg load "HKLM\$Name" $HivePath | Out-Null if ($LASTEXITCODE -ne 0) { throw "reg load $Name ($HivePath) failed" } try { & $Body "Registry::HKEY_LOCAL_MACHINE\$Name" } - finally { [gc]::Collect(); Start-Sleep -Milliseconds 500; & reg unload "HKLM\$Name" | Out-Null } + finally { + [gc]::Collect(); Start-Sleep -Milliseconds 500 + & reg unload "HKLM\$Name" | Out-Null + if ($LASTEXITCODE -ne 0) { Write-Warning "reg unload $Name failed ($LASTEXITCODE) — hive may be leaked" } + } } if ($Mode -eq 'Offline') { diff --git a/windows/branding/branding.manifest.json b/windows/branding/branding.manifest.json index 39d5e1e..dd0b2e6 100644 --- a/windows/branding/branding.manifest.json +++ b/windows/branding/branding.manifest.json @@ -19,7 +19,7 @@ "desktop": { "wallpaper": "wallpaper.jpg", "theme": "SilverMetal.theme", - "accentBgr": "00d4ff", + "accentColor": "00d4ff", "darkMode": true, "lockWallpaper": false } diff --git a/windows/branding/lib/BrandingLayers.ps1 b/windows/branding/lib/BrandingLayers.ps1 index d1b02fa..aa07ba4 100644 --- a/windows/branding/lib/BrandingLayers.ps1 +++ b/windows/branding/lib/BrandingLayers.ps1 @@ -1,4 +1,5 @@ Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' . "$PSScriptRoot\RegistryHelpers.ps1" function Set-OemInformation { @@ -34,8 +35,8 @@ function Set-DesktopBranding { Set-SmRegValue -Root $DefaultUserRoot -SubKey $p -Name 'AppsUseLightTheme' -Type DWord -Value 0 Set-SmRegValue -Root $DefaultUserRoot -SubKey $p -Name 'SystemUsesLightTheme' -Type DWord -Value 0 } - # Accent (cyan). BGR DWORD from manifest hex (stored little-endian as 0x00BBGGRR). - $bgr = [Convert]::ToInt32($Manifest.desktop.accentBgr,16) + # Accent color as COLORREF (0x00RRGGBB). #00d4ff = cyan. + $bgr = [Convert]::ToInt32($Manifest.desktop.accentColor,16) Set-SmRegValue -Root $DefaultUserRoot -SubKey 'Software\Microsoft\Windows\DWM' -Name 'AccentColor' -Type DWord -Value $bgr Set-SmRegValue -Root $DefaultUserRoot -SubKey 'Software\Microsoft\Windows\DWM' -Name 'ColorizationColor' -Type DWord -Value $bgr if (-not $Manifest.desktop.lockWallpaper) { return } diff --git a/windows/branding/lib/RegistryHelpers.ps1 b/windows/branding/lib/RegistryHelpers.ps1 index 943aed8..18122e0 100644 --- a/windows/branding/lib/RegistryHelpers.ps1 +++ b/windows/branding/lib/RegistryHelpers.ps1 @@ -1,4 +1,5 @@ Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' # Write a registry value under an arbitrary hive root (a live HKLM:/HKCU: path # OR a loaded offline hive exposed as a PSDrive). Creates intermediate keys. diff --git a/windows/tests/Branding.Tests.ps1 b/windows/tests/Branding.Tests.ps1 index 2fdced4..c50bf88 100644 --- a/windows/tests/Branding.Tests.ps1 +++ b/windows/tests/Branding.Tests.ps1 @@ -38,6 +38,7 @@ Describe 'Branding layer writers' { $k.Manufacturer | Should -Be 'SilverLABS' $k.Model | Should -Be 'SilverMetal Windows' $k.SupportURL | Should -Be 'https://silverlabs.uk' + $k.SupportHours | Should -Be '24/7 community + paid SLA' $k.Logo | Should -Be 'C:\Windows\System32\oemlogo.bmp' } @@ -58,6 +59,7 @@ Describe 'Branding layer writers' { $k = Get-ItemProperty "$script:sw\Policies\Microsoft\FVE" $k.UseCustomRecoveryMessage | Should -Be 1 $k.RecoveryMessage | Should -Be 'SilverMetal Windows. Locked out? silverlabs.uk' + $k.RecoveryUrl | Should -Be 'https://silverlabs.uk' } } @@ -70,6 +72,7 @@ Describe 'Apply-Branding -Mode Offline' { foreach ($h in @("$script:mount\Windows\System32\config\SOFTWARE","$script:mount\Users\Default\NTUSER.DAT")) { reg load 'HKLM\SM_SEED' (New-Item -ItemType File -Force $h | Select-Object -Expand FullName) 2>$null | Out-Null } + & reg unload 'HKLM\SM_SEED' 2>$null | Out-Null # The above seed is best-effort; if reg can't init an empty file, the apply # script creates the hives via reg load of the path it expects. }