Run Vili scheduled task hidden

This commit is contained in:
Meta Vens 2026-06-12 17:22:20 +01:00
commit c22913c041
2 changed files with 24 additions and 3 deletions

View file

@ -6,12 +6,13 @@ param(
)
$ErrorActionPreference = "Stop"
$RunScript = Join-Path $PSScriptRoot "run-vili-daemon.ps1"
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$RunScript`" -Port $Port -HostName `"$HostName`" -StateRoot `"$StateRoot`""
$HiddenLauncher = Join-Path $PSScriptRoot "run-hidden-powershell.vbs"
$RunScript = Join-Path $PSScriptRoot "start-vili-daemon.ps1"
$Action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "//B //nologo `"$HiddenLauncher`" -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$RunScript`" -Port $Port -HostName `"$HostName`" -StateRoot `"$StateRoot`""
$Trigger = New-ScheduledTaskTrigger -AtStartup
$UserId = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$Principal = New-ScheduledTaskPrincipal -UserId $UserId -LogonType Interactive -RunLevel Highest
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew -Hidden
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings -Force | Out-Null
Write-Host "Installed scheduled task $TaskName"

View file

@ -0,0 +1,20 @@
Option Explicit
Dim shell
Dim command
Dim i
Dim exitCode
Set shell = CreateObject("WScript.Shell")
command = QuoteArg(shell.ExpandEnvironmentStrings("%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"))
For i = 0 To WScript.Arguments.Count - 1
command = command & " " & QuoteArg(CStr(WScript.Arguments(i)))
Next
exitCode = shell.Run(command, 0, True)
WScript.Quit exitCode
Function QuoteArg(value)
QuoteArg = """" & Replace(value, """", """""") & """"
End Function