2024-07-31 13:41:45 +00:00
|
|
|
using namespace Microsoft.Win32;
|
|
|
|
|
|
|
|
$null = New-Module {
|
2024-08-09 02:19:49 +00:00
|
|
|
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
|
2024-08-07 19:05:32 +00:00
|
|
|
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
|
2024-07-31 13:41:45 +00:00
|
|
|
[RegistryKey] $key = $null;
|
|
|
|
$runOncePath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce";
|
2024-08-09 02:19:49 +00:00
|
|
|
$logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
|
2024-08-01 00:19:05 +00:00
|
|
|
$runOnceName = "PortValhalla";
|
2024-08-09 02:19:49 +00:00
|
|
|
$autologinOption = "AutoAdminLogon";
|
|
|
|
$domainOption = "DefaultDomainName";
|
|
|
|
$userOption = "DefaultUserName";
|
|
|
|
$passwordOption = "DefaultPassword";
|
2024-07-31 13:41:45 +00:00
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Gets the reghistry key containing the `RunOnce` commands.
|
|
|
|
#>
|
|
|
|
function Get-RunOnceKey {
|
|
|
|
Get-Item $runOncePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Registers a task to run the setup once after the next reboot.
|
|
|
|
|
|
|
|
.PARAMETER UserKey
|
|
|
|
The regtistry key of the user to register the task for.
|
|
|
|
#>
|
|
|
|
function Register-Setup {
|
|
|
|
param(
|
|
|
|
[RegistryKey] $UserKey
|
|
|
|
)
|
|
|
|
|
|
|
|
$key = Get-RunOnceKey $UserKey;
|
|
|
|
|
2024-08-01 00:19:05 +00:00
|
|
|
Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value (
|
|
|
|
"pwsh -Command " +
|
2024-08-09 02:08:22 +00:00
|
|
|
(& {
|
|
|
|
if ($env:PWSH_PATH) {
|
|
|
|
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);"
|
|
|
|
} else {
|
|
|
|
""
|
|
|
|
}
|
|
|
|
}) +
|
2024-08-01 00:19:05 +00:00
|
|
|
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection $env:INSTALLER_SCRIPT);" +
|
|
|
|
"`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" +
|
|
|
|
"& `$env:INSTALLER_SCRIPT;"
|
|
|
|
);
|
2024-07-31 13:41:45 +00:00
|
|
|
|
|
|
|
$key.Handle.Close();
|
|
|
|
}
|
|
|
|
|
2024-08-09 02:19:49 +00:00
|
|
|
<#
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 13:41:45 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Reboots the machine intermediately and restarts the setup after the next login.
|
|
|
|
#>
|
|
|
|
function Restart-Intermediate {
|
|
|
|
Register-Setup;
|
|
|
|
Restart-Computer;
|
|
|
|
}
|
|
|
|
}
|