diff --git a/tools/install-agent-dispatch-task.ps1 b/tools/install-agent-dispatch-task.ps1 index 63f32b5..a9959a3 100644 --- a/tools/install-agent-dispatch-task.ps1 +++ b/tools/install-agent-dispatch-task.ps1 @@ -9,15 +9,17 @@ Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $PSScriptRoot -$node = (Get-Command node.exe -ErrorAction Stop).Source $script = Join-Path $repoRoot "tools\dispatch-agent-requests.mjs" +$hiddenLauncher = Join-Path $repoRoot "tools\run-agent-dispatch-hidden.vbs" if (-not (Test-Path $script)) { throw "Missing dispatcher script at $script" } +if (-not (Test-Path $hiddenLauncher)) { + throw "Missing hidden dispatcher launcher at $hiddenLauncher" +} $argumentList = @( - "`"$script`"", "dispatch", "--repo", "`"$Repo`"", "--max", "1" @@ -27,8 +29,8 @@ if (-not [string]::IsNullOrWhiteSpace($Agent)) { } $action = New-ScheduledTaskAction ` - -Execute $node ` - -Argument ($argumentList -join " ") ` + -Execute "wscript.exe" ` + -Argument ("//B //Nologo `"$hiddenLauncher`" " + ($argumentList -join " ")) ` -WorkingDirectory $repoRoot $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) ` diff --git a/tools/run-agent-dispatch-hidden.vbs b/tools/run-agent-dispatch-hidden.vbs new file mode 100644 index 0000000..81d0a6a --- /dev/null +++ b/tools/run-agent-dispatch-hidden.vbs @@ -0,0 +1,28 @@ +Option Explicit + +Dim shell, fso, scriptDir, repoRoot, nodePath, dispatchScript, arguments, index, command + +Set shell = CreateObject("WScript.Shell") +Set fso = CreateObject("Scripting.FileSystemObject") + +scriptDir = fso.GetParentFolderName(WScript.ScriptFullName) +repoRoot = fso.GetParentFolderName(scriptDir) +nodePath = shell.ExpandEnvironmentStrings("%ProgramFiles%") & "\nodejs\node.exe" +dispatchScript = repoRoot & "\tools\dispatch-agent-requests.mjs" + +If Not fso.FileExists(nodePath) Then + nodePath = "node.exe" +End If + +arguments = "" +For index = 0 To WScript.Arguments.Count - 1 + arguments = arguments & " " & Quote(WScript.Arguments(index)) +Next + +command = Quote(nodePath) & " " & Quote(dispatchScript) & arguments +shell.CurrentDirectory = repoRoot +WScript.Quit shell.Run(command, 0, True) + +Function Quote(value) + Quote = """" & Replace(value, """", "\""") & """" +End Function