mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-05-18 19:56:25 +00:00
Add safety net for offline hive cleanup during registry import fallback
This commit is contained in:
@@ -143,6 +143,20 @@ function ImportRegistryFile {
|
||||
return
|
||||
}
|
||||
catch {
|
||||
if ($usesOfflineHive -and [bool]$regResult.HiveLeftLoaded) {
|
||||
# Safety net: if fallback failed before unloading the preloaded hive,
|
||||
# attempt cleanup here to avoid leaving HKU\Default mounted.
|
||||
$global:LASTEXITCODE = 0
|
||||
reg query "HKU\Default" | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$global:LASTEXITCODE = 0
|
||||
reg unload "HKU\Default" | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Warning "Fallback cleanup failed: unable to unload HKU\Default after fallback error (exit code: $LASTEXITCODE)."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$errorMessage = "Failed importing registry file '$path'. reg import error: $details. PowerShell fallback error: $($_.Exception.Message)"
|
||||
Write-Host $errorMessage -ForegroundColor Red
|
||||
Write-Host ""
|
||||
|
||||
Reference in New Issue
Block a user