Clean up handles during reg key handling
This commit is contained in:
parent
54d80b4bb5
commit
c90d2f7cdd
1 changed files with 11 additions and 6 deletions
|
@ -65,12 +65,15 @@ class Context {
|
|||
}
|
||||
|
||||
[void] ProcessDefaultUserKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
||||
$root = "HKLM:\DefaultUser";
|
||||
$regRoot = $root.Replace(":", "");
|
||||
$rootPath = "HKLM:\DefaultUser";
|
||||
$regRootPath = $rootPath.Replace(":", "");
|
||||
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat"
|
||||
$null = & reg load $regRoot $hivePath;
|
||||
$action.Invoke((Get-Item $root));
|
||||
reg unload $regRoot;
|
||||
$null = & reg load $regRootPath $hivePath;
|
||||
$root = Get-Item $rootPath;
|
||||
$action.Invoke($root);
|
||||
$root.Handle.Close();
|
||||
[System.GC]::Collect();
|
||||
& reg unload $regRootPath;
|
||||
}
|
||||
|
||||
[void] ProcessLogonKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
||||
|
@ -104,7 +107,9 @@ class Context {
|
|||
}
|
||||
|
||||
[void] RegisterReboot([Microsoft.Win32.RegistryKey] $userKey) {
|
||||
$null = Set-ItemProperty -Path $this.GetRunOnceKey($userKey).PSPath -Name $this.RunOnceName -Value "pwsh `"$($this.EntryPoint)`"" -Type "ExpandString";
|
||||
$runOnceKey = $this.GetRunOnceKey($userKey);
|
||||
$null = Set-ItemProperty -Path $runOnceKey.PSPath -Name $this.RunOnceName -Value "pwsh `"$($this.EntryPoint)`"" -Type "ExpandString";
|
||||
$runOnceKey.Handle.Close();
|
||||
}
|
||||
|
||||
[void] RegisterNewUserReboot() {
|
||||
|
|
Loading…
Reference in a new issue