90 lines
2.8 KiB
Plaintext
90 lines
2.8 KiB
Plaintext
Dim shell, fso, scriptsDir, projectDir, phpExe, logFile
|
|
Set shell = CreateObject("WScript.Shell")
|
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
|
scriptsDir = fso.GetParentFolderName(WScript.ScriptFullName)
|
|
projectDir = fso.GetParentFolderName(scriptsDir)
|
|
logFile = scriptsDir & "\server.log"
|
|
phpExe = ""
|
|
|
|
' --- Method 0: Bundled PHP inside scripts\php\ ---
|
|
If fso.FileExists(scriptsDir & "\php\php.exe") Then
|
|
phpExe = scriptsDir & "\php\php.exe"
|
|
End If
|
|
|
|
' --- Method 1: Scan WAMP's php folder for any version ---
|
|
If phpExe = "" Then
|
|
On Error Resume Next
|
|
If fso.FolderExists("C:\wamp64\bin\php") Then
|
|
Dim phpFolder, subFolder, latestPhp
|
|
latestPhp = ""
|
|
Set phpFolder = fso.GetFolder("C:\wamp64\bin\php")
|
|
For Each subFolder In phpFolder.SubFolders
|
|
If fso.FileExists(subFolder.Path & "\php.exe") Then
|
|
latestPhp = subFolder.Path & "\php.exe"
|
|
End If
|
|
Next
|
|
If latestPhp <> "" Then phpExe = latestPhp
|
|
End If
|
|
On Error GoTo 0
|
|
End If
|
|
|
|
' --- Method 2: where php (reads stdout directly, no temp file) ---
|
|
If phpExe = "" Then
|
|
On Error Resume Next
|
|
Dim oExec, firstLine
|
|
Set oExec = shell.Exec("cmd /c where php")
|
|
If Err.Number = 0 Then
|
|
Do While Not oExec.StdOut.AtEndOfStream
|
|
firstLine = Trim(oExec.StdOut.ReadLine())
|
|
If firstLine <> "" Then
|
|
If fso.FileExists(firstLine) Then
|
|
phpExe = firstLine
|
|
Exit Do
|
|
End If
|
|
End If
|
|
Loop
|
|
End If
|
|
On Error GoTo 0
|
|
End If
|
|
|
|
' --- Method 3: known fixed paths ---
|
|
If phpExe = "" Then
|
|
Dim candidates(2)
|
|
candidates(0) = "C:\xampp\php\php.exe"
|
|
candidates(1) = "C:\php\php.exe"
|
|
candidates(2) = shell.ExpandEnvironmentStrings("%PHPRC%\php.exe")
|
|
Dim i
|
|
For i = 0 To UBound(candidates)
|
|
On Error Resume Next
|
|
If fso.FileExists(candidates(i)) Then phpExe = candidates(i)
|
|
On Error GoTo 0
|
|
If phpExe <> "" Then Exit For
|
|
Next
|
|
End If
|
|
|
|
' --- PHP not found ---
|
|
If phpExe = "" Then
|
|
On Error Resume Next
|
|
Dim tsErr
|
|
Set tsErr = fso.OpenTextFile(logFile, 8, True)
|
|
tsErr.WriteLine Now & " - ERROR: php.exe not found. Install WAMP or add PHP to PATH."
|
|
tsErr.Close
|
|
On Error GoTo 0
|
|
WScript.Quit 1
|
|
End If
|
|
|
|
' --- Port check: exit only if actively LISTENING on 8000 ---
|
|
Dim portInUse
|
|
portInUse = shell.Run("cmd /c netstat -ano | find ""0.0.0.0:8000"" >nul 2>&1", 0, True)
|
|
If portInUse = 0 Then WScript.Quit 0
|
|
|
|
' --- Log and start server ---
|
|
On Error Resume Next
|
|
Dim ts
|
|
Set ts = fso.OpenTextFile(logFile, 8, True)
|
|
ts.WriteLine Now & " - Starting MatabPanel server with: " & phpExe
|
|
ts.Close
|
|
On Error GoTo 0
|
|
|
|
shell.Run "cmd /c cd /d """ & projectDir & """ && """ & phpExe & """ artisan serve --host=0.0.0.0 --port=8000 >> """ & logFile & """ 2>&1", 0, False
|