Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 64 additions & 11 deletions launchers/windows/Start Local RLM Cowork.vbs
Original file line number Diff line number Diff line change
@@ -1,24 +1,77 @@
Option Explicit

Dim shell, fso, scriptDir, repoDir, launcher, command, candidate, pythonw
Dim shell, fso, scriptDir, repoDir, launcher, command, pythonCommand
Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

scriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
repoDir = fso.GetParentFolderName(fso.GetParentFolderName(scriptDir))
launcher = fso.BuildPath(repoDir, "launchers\launcher.pyw")

pythonw = ""
For Each candidate In Array("pyw.exe -3.11", "pyw.exe -3", "pythonw.exe")
If shell.Run("cmd /c """ & Split(candidate, " ")(0) & """ --version", 0, True) = 0 Then
pythonw = candidate
Exit For
End If
Next
If Not fso.FileExists(launcher) Then
MsgBox "The graphical launcher could not be found:" & vbCrLf & launcher & vbCrLf & vbCrLf & _
"Extract the complete Windows bundle before starting it. Do not run the VBS file from inside the ZIP archive.", _
16, "Local RLM Cowork"
WScript.Quit 1
End If

If pythonw = "" Then
MsgBox "Python 3.11 or newer was not found. Install Python from python.org and enable the Python launcher, then double-click this file again.", 16, "Local RLM Cowork"
pythonCommand = FindPythonCommand(shell, fso)
If pythonCommand = "" Then
MsgBox "Python 3.11 or newer was not found." & vbCrLf & vbCrLf & _
"Install 64-bit Python from python.org. On the first installer screen, enable 'Add python.exe to PATH' and install the Python launcher." & vbCrLf & vbCrLf & _
"Then double-click this launcher again.", 16, "Local RLM Cowork"
WScript.Quit 1
End If

command = pythonw & " """ & launcher & """"
command = pythonCommand & " """ & launcher & """"
shell.Run command, 0, False

Function FindPythonCommand(shellObject, fileSystem)
Dim localAppData, programFiles, programFilesX86, candidates, candidate

localAppData = shellObject.ExpandEnvironmentStrings("%LocalAppData%")
programFiles = shellObject.ExpandEnvironmentStrings("%ProgramFiles%")
programFilesX86 = shellObject.ExpandEnvironmentStrings("%ProgramFiles(x86)%")

candidates = Array( _
"py.exe -3.13", _
"py.exe -3.12", _
"py.exe -3.11", _
Quote(fileSystem.BuildPath(localAppData, "Programs\Python\Python313\pythonw.exe")), _
Quote(fileSystem.BuildPath(localAppData, "Programs\Python\Python312\pythonw.exe")), _
Quote(fileSystem.BuildPath(localAppData, "Programs\Python\Python311\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFiles, "Python313\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFiles, "Python312\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFiles, "Python311\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFilesX86, "Python313\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFilesX86, "Python312\pythonw.exe")), _
Quote(fileSystem.BuildPath(programFilesX86, "Python311\pythonw.exe")), _
"pythonw.exe" _
)

For Each candidate In candidates
If CommandWorks(shellObject, CStr(candidate)) Then
FindPythonCommand = CStr(candidate)
Exit Function
End If
Next

FindPythonCommand = ""
End Function

Function CommandWorks(shellObject, candidateCommand)
Dim exitCode
On Error Resume Next
exitCode = shellObject.Run(candidateCommand & " --version", 0, True)
If Err.Number <> 0 Then
Err.Clear
CommandWorks = False
Else
CommandWorks = (exitCode = 0)
End If
On Error GoTo 0
End Function

Function Quote(value)
Quote = """" & value & """"
End Function
Loading