Files
Win11Debloat/Scripts/Helpers/RegistryPathHelpers.ps1
Jeffrey 2c360961e3 Add registry backup & restore (#566)
Starting from this commit, Win11Debloat will automatically create a registry backup every time the script is run. This registry backup can be used to revert any registry changes made by the script.
2026-05-08 21:19:52 +02:00

45 lines
1.2 KiB
PowerShell

function Split-RegistryPath {
param(
[Parameter(Mandatory)]
[string]$path
)
if ($path -notmatch '^(?<hive>HKEY_[^\\]+)(?:\\(?<subKey>.*))?$') {
return $null
}
return [PSCustomObject]@{
Hive = $matches.hive
SubKey = $matches.subKey
}
}
function Get-RegistryRootKey {
param(
[Parameter(Mandatory)]
[string]$hiveName
)
switch ($hiveName.ToUpperInvariant()) {
'HKEY_CURRENT_USER' { return [Microsoft.Win32.Registry]::CurrentUser }
'HKEY_LOCAL_MACHINE' { return [Microsoft.Win32.Registry]::LocalMachine }
'HKEY_CLASSES_ROOT' { return [Microsoft.Win32.Registry]::ClassesRoot }
'HKEY_USERS' { return [Microsoft.Win32.Registry]::Users }
'HKEY_CURRENT_CONFIG' { return [Microsoft.Win32.Registry]::CurrentConfig }
default { return $null }
}
}
function Get-RegistryFilePathForFeature {
param(
[Parameter(Mandatory)]
$Feature
)
if ($script:Params.ContainsKey('Sysprep') -or $script:Params.ContainsKey('User')) {
return Join-Path (Join-Path $script:RegfilesPath 'Sysprep') $Feature.RegistryKey
}
return Join-Path $script:RegfilesPath $Feature.RegistryKey
}