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) {
|
[void] ProcessDefaultUserKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
||||||
$root = "HKLM:\DefaultUser";
|
$rootPath = "HKLM:\DefaultUser";
|
||||||
$regRoot = $root.Replace(":", "");
|
$regRootPath = $rootPath.Replace(":", "");
|
||||||
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat"
|
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat"
|
||||||
$null = & reg load $regRoot $hivePath;
|
$null = & reg load $regRootPath $hivePath;
|
||||||
$action.Invoke((Get-Item $root));
|
$root = Get-Item $rootPath;
|
||||||
reg unload $regRoot;
|
$action.Invoke($root);
|
||||||
|
$root.Handle.Close();
|
||||||
|
[System.GC]::Collect();
|
||||||
|
& reg unload $regRootPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] ProcessLogonKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
[void] ProcessLogonKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
||||||
|
@ -104,7 +107,9 @@ class Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] RegisterReboot([Microsoft.Win32.RegistryKey] $userKey) {
|
[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() {
|
[void] RegisterNewUserReboot() {
|
||||||
|
|
Loading…
Reference in a new issue