Login to users for configuration

This commit is contained in:
Manuel Thalmann 2024-08-09 04:19:49 +02:00
parent c79d632639
commit cb2735b909
4 changed files with 112 additions and 4 deletions
scripts/Windows/Scripts

View file

@ -1,10 +1,16 @@
using namespace Microsoft.Win32;
$null = New-Module {
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
[RegistryKey] $key = $null;
$runOncePath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce";
$logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$runOnceName = "PortValhalla";
$autologinOption = "AutoAdminLogon";
$domainOption = "DefaultDomainName";
$userOption = "DefaultUserName";
$passwordOption = "DefaultPassword";
<#
.SYNOPSIS
@ -45,6 +51,56 @@ $null = New-Module {
$key.Handle.Close();
}
<#
.SYNOPSIS
Sets the user to login automatically on boot.
.PARAMETER Name
The name of the user to login automatically.
#>
function Set-AutologinUser {
param(
[string] $Name
)
Set-ItemProperty $autologinOption -Name $autologinOption "1";
if (-not $Name) {
$Name = Get-SetupUser;
}
$options = @{
$domainOption = "";
$userOption = $Name;
$passwordOption = "";
};
foreach ($key in $options.Keys) {
Set-ItemProperty -Name $key
$displayName = Get-UserConfig -UserName $name "displayName";
$userArguments = @{
name = $name;
};
if ($displayName) {
$userArguments.fullName = $displayName;
} -Value $options[$key];
}
}
<#
.SYNOPSIS
Disables the automatic login.
#>
function Disable-Autologin {
Set-ItemProperty $logonPath -Name $autologinOption "0";
foreach ($key in @($domainOption, $userOption, $passwordOption)) {
Remove-ItemProperty $logonPath -Name $key -ErrorAction SilentlyContinue;
}
}
<#
.SYNOPSIS
Reboots the machine intermediately and restarts the setup after the next login.

View file

@ -101,10 +101,6 @@ $null = New-Module {
Set-LocalUser $name -PasswordNeverExpires $true;
Set-LocalUser $name -PasswordNeverExpires $false;
}
if (-not (Get-UserConfig -UserName $name "microsoftAccount")) {
net user $name /logonpasswordchg:yes;
}
}
}
};