From f47359440fa952323fd4aad24161f826150b2d84 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 24 May 2026 11:05:01 +0200 Subject: [PATCH] Fix access denied when unloading default user registry hive Force .NET garbage collection before reg.exe unload to release open RegistryKey handles left by PowerShell registry cmdlets. Co-Authored-By: Claude Sonnet 4.6 --- powershell/Remove-BuiltInApps.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powershell/Remove-BuiltInApps.ps1 b/powershell/Remove-BuiltInApps.ps1 index 5c04e06..fc5739d 100644 --- a/powershell/Remove-BuiltInApps.ps1 +++ b/powershell/Remove-BuiltInApps.ps1 @@ -318,6 +318,8 @@ function Set-DefaultUserProfileDefaults { finally { if ($HiveWasLoaded) { Write-Host "Unloading default user registry hive..." -ForegroundColor Cyan + [GC]::Collect() + [GC]::WaitForPendingFinalizers() & reg.exe unload "HKU\DefaultUser" | Out-Null if ($LASTEXITCODE -ne 0) {