Store the artifact path in an individual script
This commit is contained in:
parent
5bbe197ec6
commit
50b4a30256
|
@ -4,8 +4,10 @@ using namespace System.Management.Automation.Host;
|
|||
|
||||
$null = New-Module {
|
||||
. "$PSScriptRoot/Config.ps1";
|
||||
. "$PSScriptRoot/Scripting.ps1";
|
||||
. "$PSScriptRoot/../Scripts/SoftwareManagement.ps1";
|
||||
. "$PSScriptRoot/../Types/OneShotTask.ps1";
|
||||
. "$PSScriptRoot/../../Windows/Scripts/Constants.ps1";
|
||||
. "$PSScriptRoot/../../Windows/Scripts/Hooks.ps1";
|
||||
. "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1";
|
||||
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
|
||||
|
@ -15,8 +17,10 @@ $null = New-Module {
|
|||
$logName = "Application";
|
||||
$oneShotTrigger = 1337;
|
||||
$taskOption = "OneShotTask";
|
||||
# ToDo: Store "ProgramData/PortValhalla" path somewhere as const
|
||||
$errorPath = "$env:ProgramData/PortValhalla/error.txt";
|
||||
|
||||
$getErrorPath = {
|
||||
Join-Path (Get-ArtifactRoot) "error.txt";
|
||||
};
|
||||
|
||||
$getUserName = {
|
||||
"$(Get-SetupUser)OneShot";
|
||||
|
@ -314,11 +318,12 @@ $null = New-Module {
|
|||
|
||||
$null = New-LocalUser -Name $user -Password (ConvertTo-SecureString -AsPlainText $password);
|
||||
Add-LocalGroupMember -Member $user @adminGroup;
|
||||
$logPath = Join-Path (Get-ArtifactRoot) "OneShotTask.log";
|
||||
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList";
|
||||
$null = New-Item -Force -ErrorAction SilentlyContinue $path;
|
||||
Set-ItemProperty $path -Name $user -Value 0;
|
||||
|
||||
$action = New-ScheduledTaskAction -Execute "pwsh" -Argument "-Command & { $([string](Get-StartupCommand)) } 2>&1 | Tee-Object -FilePath `$env:ProgramData/PortValhalla/OneShotTask.log";
|
||||
$action = New-ScheduledTaskAction -Execute "pwsh" -Argument "-Command & { $([string](Get-StartupCommand)) } 2>&1 | Tee-Object -FilePath $(ConvertTo-Injection $logPath)";
|
||||
schtasks /Create /SC ONEVENT /EC $logName /MO "*[System[Provider[@Name='$logName'] and EventID=$($oneShotTrigger)]]" /TR cmd.exe /TN $tempTask;
|
||||
$trigger = (Get-ScheduledTask $tempTask).Triggers;
|
||||
$null = Register-ScheduledTask -Force $oneShotTaskName -Action $action -Trigger $trigger -RunLevel Highest -User $user -Password $password;
|
||||
|
@ -349,6 +354,7 @@ $null = New-Module {
|
|||
[OneShotTask] $Task
|
||||
)
|
||||
|
||||
$errorPath = & $getErrorPath;
|
||||
& $taskSetter $Task;
|
||||
|
||||
& {
|
||||
|
@ -408,6 +414,7 @@ $null = New-Module {
|
|||
}
|
||||
}
|
||||
catch {
|
||||
$errorPath = & $getErrorPath;
|
||||
Set-Content -Path $errorPath -Value $Error;
|
||||
Set-UserPermissions $errorPath;
|
||||
}
|
||||
|
|
7
scripts/Windows/Scripts/Constants.ps1
Normal file
7
scripts/Windows/Scripts/Constants.ps1
Normal file
|
@ -0,0 +1,7 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets the path to a directory to store setup artifacts.
|
||||
#>
|
||||
function Get-ArtifactRoot {
|
||||
Join-Path "$env:ProgramData" "PortValhalla";
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
. "$PSScriptRoot/Constants.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Security.ps1";
|
||||
|
||||
<#
|
||||
|
@ -13,7 +14,7 @@ function Get-WslDistributionName {
|
|||
Gets the path to the directory containing the WSL distribution.
|
||||
#>
|
||||
function Get-WslDistributionPath {
|
||||
return "$env:ProgramData/PortValhalla/$(Get-WslDistributionName)";
|
||||
Join-Path (Get-ArtifactRoot) (Get-WslDistributionName);
|
||||
}
|
||||
|
||||
<#
|
||||
|
|
Loading…
Reference in a new issue