Add a method for cleaning up artifacts during setup
This commit is contained in:
parent
bf59f2e3a3
commit
f791ec1eff
1 changed files with 28 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
. "$PSScriptRoot/../Scripts/Context.ps1";
|
||||
$uacDisablerName = "PortValhalla UAC Disabler";
|
||||
$cleanupName = "PortValhalla Cleanup";
|
||||
|
||||
function New-PersonalUser([Context] $context)
|
||||
{
|
||||
|
@ -44,6 +45,22 @@ function New-PersonalUser([Context] $context)
|
|||
Restart-Computer;
|
||||
exit;
|
||||
}
|
||||
elseif ((Get-ScheduledTask $uacDisablerName))
|
||||
{
|
||||
while ((Get-ScheduledTask $uacDisablerName) -ne "Ready")
|
||||
{
|
||||
Start-Sleep 1;
|
||||
}
|
||||
|
||||
$taskInfo = Get-ScheduledTask $uacDisablerName;
|
||||
|
||||
if ($taskInfo.LastTaskResult -ne 0)
|
||||
{
|
||||
Write-Error "Disabling UAC was unsuccessful.";
|
||||
}
|
||||
|
||||
Start-ScheduledTask $cleanupName;
|
||||
}
|
||||
}
|
||||
|
||||
function Enable-UACNextLogin() {
|
||||
|
@ -62,4 +79,15 @@ function Enable-UACNextLogin() {
|
|||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest;
|
||||
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger;
|
||||
$null = Register-ScheduledTask $uacDisablerName -InputObject $task;
|
||||
|
||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
||||
[string]::Join(
|
||||
" ",
|
||||
@(
|
||||
"-c",
|
||||
"Unregister-ScheduledTask -Force $uacDisablerName;",
|
||||
"Unregister-ScheduledTask -Force $cleanupName;")));
|
||||
|
||||
$task = New-ScheduledTask -Action $action -Principal $principal;
|
||||
$null = Register-ScheduledTask $cleanupName -InputObject $task;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue