Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
dir = fso.GetParentFolderName(WScript.ScriptFullName)

pythonExe = ""

Function TryPath(p)
  If fso.FileExists(p) Then
    TryPath = p
  Else
    TryPath = ""
  End If
End Function

pythonExe = TryPath(sh.ExpandEnvironmentStrings("%LocalAppData%") & "\Programs\Python\Python312\pythonw.exe")
If pythonExe = "" Then pythonExe = TryPath(sh.ExpandEnvironmentStrings("%LocalAppData%") & "\Programs\Python\Python311\pythonw.exe")
If pythonExe = "" Then pythonExe = TryPath(sh.ExpandEnvironmentStrings("%LocalAppData%") & "\Programs\Python\Python310\pythonw.exe")

If pythonExe = "" Then
  On Error Resume Next
  Set proc = sh.Exec("where pythonw")
  Do While proc.Status = 0
    WScript.Sleep 50
  Loop
  If proc.ExitCode = 0 Then
    lines = Split(proc.StdOut.ReadAll, vbCrLf)
    If UBound(lines) >= 0 Then pythonExe = Trim(lines(0))
  End If
  On Error GoTo 0
End If

If pythonExe = "" Then
  MsgBox "Python not found." & vbCrLf & "Install Python 3.10+ from python.org", 16, "Start Failed"
  WScript.Quit 1
End If

sh.Run """" & pythonExe & """ """ & dir & "\launch.py""", 0, False
