Dim shell, fso, scriptsDir, phpExe, logFile Set shell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") scriptsDir = fso.GetParentFolderName(WScript.ScriptFullName) logFile = scriptsDir & "\ftp-server.log" ' --- Find PHP --- phpExe = "" Dim candidates(4) candidates(0) = scriptsDir & "\php\php.exe" candidates(1) = "C:\xampp\php\php.exe" candidates(2) = "C:\php\php.exe" candidates(3) = "C:\wamp64\bin\php\php.exe" candidates(4) = "C:\wamp\bin\php\php.exe" Dim i For i = 0 To 4 If fso.FileExists(candidates(i)) Then phpExe = candidates(i) Exit For End If Next ' --- Try WAMP versioned folders --- If phpExe = "" Then Dim wampBase(1) wampBase(0) = "C:\wamp64\bin\php" wampBase(1) = "C:\wamp\bin\php" Dim w For w = 0 To 1 If fso.FolderExists(wampBase(w)) Then Dim subF For Each subF In fso.GetFolder(wampBase(w)).SubFolders phpExe = subF.Path & "\php.exe" Next If fso.FileExists(phpExe) Then Exit For phpExe = "" End If Next End If If phpExe = "" Then On Error Resume Next Dim ts Set ts = fso.OpenTextFile(logFile, 8, True) ts.WriteLine Now & " - ERROR: php.exe not found in any known location" ts.Close WScript.Quit 1 End If ' --- Skip if already running on port 2121 --- Dim portInUse portInUse = shell.Run("cmd /c netstat -ano | find "":2121 "" >nul 2>&1", 0, True) If portInUse = 0 Then WScript.Quit 0 ' --- Log start --- On Error Resume Next Dim ts2 Set ts2 = fso.OpenTextFile(logFile, 8, True) ts2.WriteLine Now & " - Starting FTP server with: " & phpExe ts2.Close On Error GoTo 0 ' --- Start FTP server silently in background --- shell.Run "cmd /c """ & phpExe & """ -d display_errors=0 """ & scriptsDir & "\ftp-server.php"" >> """ & logFile & """ 2>&1", 0, False