Hide agent dispatch scheduled task

This commit is contained in:
Meta Vens 2026-05-20 18:05:16 +01:00
commit 560ee5cc85
2 changed files with 34 additions and 4 deletions

View file

@ -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) `

View file

@ -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