35 lines
1.3 KiB
PowerShell
35 lines
1.3 KiB
PowerShell
# Replace any stale Comfy host agent, then start THIS clone's agent on 8199.
|
|
# Called by launch-comfy-host-agent.vbs (Startup / Desktop / Start Menu).
|
|
# -Wait: run in-foreground for Task Scheduler (keeps task marked Running).
|
|
param([switch]$Wait)
|
|
$ErrorActionPreference = 'SilentlyContinue'
|
|
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
|
$node = 'C:\Program Files\nodejs\node.exe'
|
|
$agent = Join-Path $root 'scripts\comfy-host-agent.mjs'
|
|
if (-not (Test-Path $node)) { throw "Missing $node" }
|
|
if (-not (Test-Path $agent)) { throw "Missing $agent" }
|
|
|
|
Get-CimInstance Win32_Process -Filter "Name='node.exe'" |
|
|
Where-Object { $_.CommandLine -match 'comfy-host-agent' } |
|
|
ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
|
|
|
|
Get-NetTCPConnection -LocalPort 8199 -State Listen -ErrorAction SilentlyContinue |
|
|
ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
|
|
|
|
Start-Sleep -Milliseconds 400
|
|
|
|
if ($Wait) {
|
|
Set-Location $root
|
|
& $node $agent
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
$psi = New-Object System.Diagnostics.ProcessStartInfo
|
|
$psi.FileName = $node
|
|
$psi.Arguments = "`"$agent`""
|
|
$psi.WorkingDirectory = $root
|
|
$psi.UseShellExecute = $false
|
|
$psi.CreateNoWindow = $true
|
|
$psi.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
|
|
[void][System.Diagnostics.Process]::Start($psi)
|