PortValhalla/scripts/Windows/Scripts/Registry.ps1

20 lines
563 B
PowerShell
Raw Normal View History

2024-08-05 18:07:39 +00:00
using namespace Microsoft.Win32;
$null = New-Module {
function Edit-DefaultUserKey {
param(
[scriptblock] $Action
)
$rootPath = "HKLM:\DefaultUser";
$regRootPath = $rootPath -replace "^(\w+):([\\/]|$)","`$1`$2";
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat";
$null = & reg load $regRootPath $hivePath;
[RegistryKey] $root = Get-Item $rootPath;
& $Action -Key $root;
$root.Handle.Close();
[System.GC]::Collect();
& reg unload $regRootPath;
}
}