Add scripts for handling auto login
This commit is contained in:
parent
9cd6834819
commit
63906c53ce
1 changed files with 33 additions and 0 deletions
|
@ -73,6 +73,11 @@ class Context {
|
||||||
reg unload $regRoot;
|
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() {
|
[Microsoft.Win32.RegistryKey] GetRunOnceKey() {
|
||||||
return $this.GetRunOnceKey($null);
|
return $this.GetRunOnceKey($null);
|
||||||
}
|
}
|
||||||
|
@ -110,6 +115,34 @@ class Context {
|
||||||
$this.ProcessDefaultUserKey({ param ($root) Remove-Item -Path $this.GetRunOnceKey($root).PSPath });
|
$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() {
|
[void] Reboot() {
|
||||||
Write-Host "Restarting Computer...";
|
Write-Host "Restarting Computer...";
|
||||||
$this.RegisterReboot();
|
$this.RegisterReboot();
|
||||||
|
|
Loading…
Reference in a new issue