diff --git a/scripts/Windows/OS/Manage.ps1 b/scripts/Windows/OS/Manage.ps1 index 6c86573f..e3641d12 100644 --- a/scripts/Windows/OS/Manage.ps1 +++ b/scripts/Windows/OS/Manage.ps1 @@ -5,6 +5,7 @@ using namespace System.Security.Principal; . "$PSScriptRoot/../Scripts/WSL.ps1"; $null = New-Module { + . "$PSScriptRoot/../Scripts/Constants.ps1"; . "$PSScriptRoot/../Scripts/Deployment.ps1"; . "$PSScriptRoot/../Scripts/Hooks.ps1"; . "$PSScriptRoot/../Scripts/PowerManagement.ps1"; @@ -218,7 +219,9 @@ $null = New-Module { $script = { param( $TaskName, - $UserName + $UserName, + $ProjectRoot, + $ArtifactRoot ) $user = Get-LocalUser $UserName; @@ -226,10 +229,21 @@ $null = New-Module { Remove-LocalUser $user; Get-CimInstance Win32_UserProfile | Where-Object { $_.SID -eq $sid } | Remove-CimInstance; Unregister-ScheduledTask -Confirm:$false $TaskName; + Remove-Item -Recurse -Force "$ProjectRoot"; + Remove-Item -Recurse -Force "$ArtifactRoot"; }; $trigger = New-ScheduledTaskTrigger -AtStartup; - $task = New-ScheduledTaskAction -Execute "pwsh" -Argument "-Command & { $script } $(ConvertTo-Injection $taskName) $(ConvertTo-Injection $setupUser)"; + + $task = New-ScheduledTaskAction -Execute "pwsh" ` + -Argument (@( + "-Command & { $script }", + (ConvertTo-Injection $taskName), + (ConvertTo-Injection $setupUser), + (ConvertTo-Injection $env:VALHALLA_ROOT), + (ConvertTo-Injection (Get-ArtifactRoot)) + ) -join " "); + $null = Register-ScheduledTask -Force $taskName -Action $task -Trigger $trigger -RunLevel Highest -User "SYSTEM"; Set-Stage ([WindowsInstallerStage]::Completed); Enable-UAC; diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 index ff0ec8a8..2d6da0be 100644 --- a/scripts/Windows/OS/Setup.ps1 +++ b/scripts/Windows/OS/Setup.ps1 @@ -232,6 +232,7 @@ function Start-Setup { -Script ( "powershell -Command " + ($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") + + "`$env:VALHALLA_ROOT = $(Get-PathInjection $env:REMOTE_PROJECT_PATH);" + "`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" + "`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" + "`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" + diff --git a/scripts/Windows/Scripts/PowerManagement.ps1 b/scripts/Windows/Scripts/PowerManagement.ps1 index 9e8f8dbd..3121b6c9 100644 --- a/scripts/Windows/Scripts/PowerManagement.ps1 +++ b/scripts/Windows/Scripts/PowerManagement.ps1 @@ -54,8 +54,9 @@ $null = New-Module { Generates a command for running the installer using `pwsh`. #> function Get-StartupCommand { - ($env:PWSH_PATH ? "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" : "") + ($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") + + "`$env:VALHALLA_ROOT = $(ConvertTo-Injection $env:VALHALLA_ROOT);" + + ($env:PWSH_PATH ? "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" : "") + ($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection ([System.IO.Path]::GetFullPath($env:BACKUP_ARCHIVE)));" : "") + "`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" + "`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +