' Start the Comfy host agent with no window. Safe to run when Cursor is closed. ' Uses the "AIGen Comfy Host Agent" scheduled task when it exists. Option Explicit Dim sh, fso, root, node, agent, rc Set sh = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") If AgentRunning() Then WScript.Quit 0 On Error Resume Next rc = sh.Run("schtasks /run /tn ""AIGen Comfy Host Agent""", 0, True) On Error GoTo 0 WScript.Sleep 1200 If AgentRunning() Then WScript.Quit 0 root = fso.GetParentFolderName(WScript.ScriptFullName) root = fso.GetParentFolderName(root) node = """C:\Program Files\nodejs\node.exe""" agent = """" & root & "\scripts\comfy-host-agent.mjs""" If Not fso.FileExists(Replace(node, """", "")) Then WScript.Quit 1 sh.CurrentDirectory = root sh.Run node & " " & agent, 0, False Function AgentRunning() Dim svc, query, item AgentRunning = False Set svc = GetObject("winmgmts:\\.\root\cimv2") Set query = svc.ExecQuery("SELECT CommandLine FROM Win32_Process WHERE Name='node.exe'") For Each item In query If InStr(LCase("" & item.CommandLine), "comfy-host-agent") > 0 Then AgentRunning = True Exit Function End If Next End Function