mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-05-18 11:46:18 +00:00
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.
This commit is contained in:
44
Scripts/Helpers/RegistryPathHelpers.ps1
Normal file
44
Scripts/Helpers/RegistryPathHelpers.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user