Move UAC handling to context
This commit is contained in:
parent
98dfa910be
commit
0996dbecaf
2 changed files with 15 additions and 18 deletions
|
@ -64,30 +64,14 @@ function New-PersonalUser([Context] $context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-SystemPolicyKey() {
|
|
||||||
[OutputType([Microsoft.Win32.RegistryKey])]
|
|
||||||
param()
|
|
||||||
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
|
|
||||||
return Get-Item "$keyPath";
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-UACState() {
|
|
||||||
return Get-ItemPropertyValue -Path (Get-SystemPolicyKey).PSPath -Name "EnableLUA";
|
|
||||||
}
|
|
||||||
|
|
||||||
function Set-UACState([bool] $value) {
|
|
||||||
$null = Set-ItemProperty -Path (Get-SystemPolicyKey).PSPath -Name "EnableLUA" -Value [int]$value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Enable-UACNextLogin([Context] $context) {
|
function Enable-UACNextLogin([Context] $context) {
|
||||||
Set-UACState $true;
|
$context.SetUACState($true);
|
||||||
$tempTask = "PortValhalla Temp";
|
$tempTask = "PortValhalla Temp";
|
||||||
$autoLoginName = "PortValhalla AutoLogin Setup";
|
$autoLoginName = "PortValhalla AutoLogin Setup";
|
||||||
$uacDisablerName = "PortValhalla UAC Disabler";
|
$uacDisablerName = "PortValhalla UAC Disabler";
|
||||||
$autoLoginTrigger = Get-Random -Maximum 65535;
|
$autoLoginTrigger = Get-Random -Maximum 65535;
|
||||||
$uacDisablerTrigger = Get-Random -Maximum 65535;
|
$uacDisablerTrigger = Get-Random -Maximum 65535;
|
||||||
|
|
||||||
$key = Get-SystemPolicyKey;
|
|
||||||
$context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord");
|
$context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord");
|
||||||
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
||||||
|
|
||||||
|
@ -107,11 +91,11 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
$uacDisablerTrigger,
|
$uacDisablerTrigger,
|
||||||
"PortValhalla UAC Disabler",
|
"PortValhalla UAC Disabler",
|
||||||
@(
|
@(
|
||||||
"Set-ItemProperty '$($key.PSPath)' -Name 'EnableLUA' -Value 0 -Type DWord;",
|
|
||||||
"Unregister-ScheduledTask -Confirm:`$false '$autoLoginName';",
|
"Unregister-ScheduledTask -Confirm:`$false '$autoLoginName';",
|
||||||
"Unregister-ScheduledTask -Confirm:`$false '$uacDisablerName';",
|
"Unregister-ScheduledTask -Confirm:`$false '$uacDisablerName';",
|
||||||
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
||||||
"`$context = [Context]::new();",
|
"`$context = [Context]::new();",
|
||||||
|
"`$context.SetUACState(`$false);",
|
||||||
"`$context.Remove('$autoLoginTriggerProperty');",
|
"`$context.Remove('$autoLoginTriggerProperty');",
|
||||||
"`$context.Remove('$uacDisablerTriggerProperty');",
|
"`$context.Remove('$uacDisablerTriggerProperty');",
|
||||||
"`$context.DeregisterNewUserReboot();",
|
"`$context.DeregisterNewUserReboot();",
|
||||||
|
|
|
@ -148,6 +148,11 @@ class Context {
|
||||||
$action.Invoke($key);
|
$action.Invoke($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Microsoft.Win32.RegistryKey] GetSystemPolicyKey() {
|
||||||
|
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
|
||||||
|
return Get-Item "$keyPath";
|
||||||
|
}
|
||||||
|
|
||||||
[Microsoft.Win32.RegistryKey] GetRunOnceKey() {
|
[Microsoft.Win32.RegistryKey] GetRunOnceKey() {
|
||||||
return $this.GetRunOnceKey($null);
|
return $this.GetRunOnceKey($null);
|
||||||
}
|
}
|
||||||
|
@ -169,6 +174,14 @@ class Context {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[bool] GetUACState() {
|
||||||
|
return [bool](Get-ItemPropertyValue -Path ($this.GetSystemPolicyKey().PSPath) -Name "EnableLUA");
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] SetUACState([bool] $value) {
|
||||||
|
$null = Set-ItemProperty -Path ($this.GetSystemPolicyKey().PSPath) -Name "EnableLUA" -Value [int]$value;
|
||||||
|
}
|
||||||
|
|
||||||
[void] RegisterReboot() {
|
[void] RegisterReboot() {
|
||||||
$this.RegisterReboot($null);
|
$this.RegisterReboot($null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue