Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
' Get the directory of this script (scripts\), then go up to app root
scriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
appRoot = fso.GetParentFolderName(scriptDir)
WshShell.CurrentDirectory = appRoot

' Set env vars for the child process (inherited via WshShell.Run)
Set procEnv = WshShell.Environment("Process")
procEnv("PYTHONPATH") = appRoot & "\app\src"
procEnv("LEDGRAB_CONFIG_PATH") = appRoot & "\app\config\default_config.yaml"

' If launched as Windows autostart (via the SMSTARTUP shortcut), suppress the
' browser auto-open. Manual launches (desktop / start menu) pass no args.
For Each arg In WScript.Arguments
    If arg = "--autostart" Then
        procEnv("LEDGRAB_AUTOSTART") = "1"
        Exit For
    End If
Next

' Use embedded python.exe (NOT pythonw.exe) with WindowStyle=0.
' Same pattern as the Media Server sibling app.
embeddedPython = appRoot & "\python\python.exe"
If fso.FileExists(embeddedPython) Then
    WshShell.Run """" & embeddedPython & """ -m ledgrab", 0, False
Else
    WshShell.Run "python -m ledgrab", 0, False
End If
