' captajaus_start.vbs
' Lanza captajaus_tray.js en modo silencioso (sin ventana).
' Incluye guardia anti-duplicados: si ya hay un node corriendo
' con captajaus_tray.js en su línea de comandos, no lanza otro.

Dim oWMI, oProcs, count

' Contar instancias actuales de captajaus_tray.js
Set oWMI   = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set oProcs = oWMI.ExecQuery( _
    "SELECT * FROM Win32_Process " & _
    "WHERE CommandLine LIKE '%captajaus_tray.js%' " & _
    "  AND Name = 'node.exe'")

count = 0
For Each p In oProcs : count = count + 1 : Next

If count = 0 Then
    Dim oShell
    Set oShell = CreateObject("WScript.Shell")
    oShell.CurrentDirectory = "C:\xampp\htdocs\captajaus\pm2-tray"
    ' 0 = ventana oculta, False = no esperar
    oShell.Run """C:\Program Files\nodejs\node.exe"" captajaus_tray.js", 0, False
    Set oShell = Nothing
End If

Set oProcs = Nothing
Set oWMI   = Nothing
