diff --git a/scripts/install-vili-task.ps1 b/scripts/install-vili-task.ps1 index 375c73c..247df07 100644 --- a/scripts/install-vili-task.ps1 +++ b/scripts/install-vili-task.ps1 @@ -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" diff --git a/scripts/run-hidden-powershell.vbs b/scripts/run-hidden-powershell.vbs new file mode 100644 index 0000000..2a4d85b --- /dev/null +++ b/scripts/run-hidden-powershell.vbs @@ -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