Add scripts for handling auto login

This commit is contained in:
Manuel Thalmann 2023-06-25 18:25:52 +02:00
parent 9cd6834819
commit 63906c53ce

View file

@ -73,6 +73,11 @@ class Context {
reg unload $regRoot;
}
[void] ProcessLogonKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
$key = Get-Item "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon";
$action.Invoke($key);
}
[Microsoft.Win32.RegistryKey] GetRunOnceKey() {
return $this.GetRunOnceKey($null);
}
@ -110,6 +115,34 @@ class Context {
$this.ProcessDefaultUserKey({ param ($root) Remove-Item -Path $this.GetRunOnceKey($root).PSPath });
}
[void] SetAutologin($user, $pw) {
$this.ProcessLogonKey(
{
param ($logon)
$path = $logon.PSPath;
Set-ItemProperty $path -Name "AutoAdminLogon" 1;
Set-ItemProperty $path -Name "DefaultUserName" $user;
if ($password) {
Set-ItemProperty $path -Name "DefaultPassword" $password;
} else {
Remove-ItemProperty $path -Name "DefaultPassword";
}
});
}
[void] RemoveAutologin() {
$this.ProcessLogonKey(
{
param ($logon)
$path = $logon.PSPath;
Remove-ItemProperty $path -Name "AutoAdminLogon";
Remove-ItemProperty $path -Name "DefaultDomainName";
Remove-ItemProperty $path -Name "DefaultUserName";
Remove-ItemProperty $path -Name "DefaultPassword";
});
}
[void] Reboot() {
Write-Host "Restarting Computer...";
$this.RegisterReboot();