EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Tools (https://www.eqemulator.org/forums/forumdisplay.php?f=593)
-   -   Wrapper to start EQEmu on Windows (https://www.eqemulator.org/forums/showthread.php?t=24020)

Knightly 12-26-2007 05:11 PM

Wrapper to start EQEmu on Windows
 
I wrote this vbscript a while back when I kept getting annoyed that my batch file was taking too long. It doesn't have Angelox's Day/Night scripts, but that wouldn't be too hard to add.

It's also an example of bad coding because most everything is hard-coded. But if anyone wants it, here it is ;-). I used to use it in a login script for my EQEmulator Server that would auto-login and lock the screen.

Code:

numSecondsToSleep = 10 'Number of seconds to sleep before continuing to launch programs
numMinutesWorldTimeout = 5 'How many minutes should we give World to connect to the login server before we give up
Const ForReading = 1

'Get the arguments
Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
          If InStr(objArgs(0), ":\") or InStr(objArgs(0), "\\") Then
            strPathToEQEmuFolder = objArgs(0)
        End If
End If

If InStr(strPathToEQEmuFolder, ":\") > 0 or InStr(strPathToEQEmuFolder, "\\") > 0 Then
        binDoCleanup = True
       
        'Fix the path if needed
        If Right(strPathToEQEmuFolder, 1) = "\" Then
                'Do nothing
        Else
                strPathToEQEmuFolder = strPathToEQEmuFolder & "\"
        End If
       
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Check to make sure the path to the stored files exists
        If True = objFSO.FolderExists(strPathToEQEmuFolder) Then
                Set objShell = CreateObject("WScript.Shell")
                objShell.CurrentDirectory = strPathToEQEmuFolder
                strPathToMiniLogin = strPathToEQEmuFolder & "MiniLogin.exe"
                'If we were provided with the path to wget.exe and it exists, then make sure it exists
                If True = objFSO.FileExists(strPathToMiniLogin) Then
                        strPathToWorld = strPathToEQEmuFolder & "world.exe"
                        If True = objFSO.FileExists(strPathToWorld) Then
                                strPathToEQLaunch = strPathToEQEmuFolder & "eqlaunch.exe"
                                If True = objFSO.FileExists(strPathToEQLaunch) Then
                                        'Correct for Spaces in the File Names
                                        If InStr(strPathToMiniLogin, " ") Then
                                                strPathToMiniLoginShell = chr(34) & strPathToMiniLogin & chr(34)
                                        Else
                                                strPathToMiniLoginShell = strPathToMiniLogin
                                        End If
                                       
                                        If InStr(strPathToWorld, " ") Then
                                                strPathToWorldShell = chr(34) & strPathToWorld & chr(34)
                                        Else
                                                strPathToWorldShell = strPathToWorld
                                        End If
                                       
                                        If InStr(strPathToEQLaunch, " ") Then
                                                strPathToEQLaunchShell = chr(34) & strPathToEQLaunch & chr(34)
                                        Else
                                                strPathToEQLaunchShell = strPathToEQLaunch
                                        End If
                                       
                                        'Start MiniLogin
                                        objShell.Exec(strPathToMiniLoginShell)
                                        Wscript.Sleep numSecondsToSleep * 1000
                                        If True = ProcessIsRunning("MiniLogin.exe") Then
                                                'Start World
                                                objShell.Exec(strPathToWorldShell)
                                                Wscript.Sleep numSecondsToSleep * 1000
                                                If True = ProcessIsRunning("World.exe") Then
                                                        'Find the debug log for World
                                                        Set objFolder = objFSO.GetFolder(strPathToEQEmuFolder & "logs")
                                                        Set objLogFiles = objFolder.Files
                                                        dateCurrentWorldLog = CDate("01/01/0000 00:00:00 PM")
                                                        For Each curFile in objLogFiles
                                                                If InStr(lcase(curFile.Name), "debug_world") Then
                                                                        If curFile.DateLastModified > dateCurrentWorldLog Then
                                                                                strPathToCurrentWorldLog = curFile.Path
                                                                                dateCurrentWorldLog = curFile.DateLastModified
                                                                        End If
                                                                End If
                                                        Next
                                                        If dateCurrentWorldLog <> CDate("01/01/0000 00:00:00 PM") Then
                                                                If objFSO.FileExists(strPathToCurrentWorldLog) Then
                                                                        i = 0
                                                                        binConnected = False
                                                                        Do
                                                                                Wscript.Sleep numSecondsToSleep * 1000
                                                                                i = i + numSecondsToSleep
                                                                                Set objCurrentWorldLog = objFSO.OpenTextFile(strPathToCurrentWorldLog, ForReading)
                                                                                strCurrentWorldLog = objCurrentWorldLog.ReadAll
                                                                                objCurrentWorldLog.Close
                                                                                If InStr(strCurrentWorldLog, "[WORLD__LS] Connected to Loginserver:") Then
                                                                                        binConnected = True
                                                                                End If
                                                                        Loop Until i > (numMinutesWorldTimeout * 60) or True = binConnected
                                                                       
                                                                        If True = binConnected Then
                                                                                objShell.Exec(strPathToEQLaunchShell & " zone")
                                                                                Wscript.Sleep numSecondsToSleep * 1000
                                                                                If True = ProcessIsRunning("eqlaunch.exe") Then
                                                                                        Wscript.Sleep numSecondsToSleep * 1000
                                                                                        If True = ProcessIsRunning("zone.exe") Then
                                                                                                varResponse = MsgBox("Your EQEmulator Server should now be running.  Do you want to shut it down?", vbYesNo + vbInformation + vbDefaultButton2, "EQEmulator Wrapper")
                                                                                                If vbNo = varResponse Then
                                                                                                        binDoCleanup = False
                                                                                                End If
                                                                                        Else
                                                                                                Wscript.Echo "ERROR - zone.exe did not start."
                                                                                        End If
                                                                                Else
                                                                                        Wscript.Echo "ERROR - Could not start eqlaunch.exe"
                                                                                End If
                                                                        Else
                                                                                Wscript.Echo "ERROR - Timed out while waiting for Loginserver connection: " & numMinutesWorldTimeout & " minute timeout."
                                                                        End If
                                                                Else
                                                                        Wscript.Echo "ERROR - The system reports that the current log file does not exist: " & strPathToCurrentWorldLog
                                                                End if
                                                        Else
                                                                Wscript.Echo "ERROR - Could not find the date of the latest log file in " & strPathToEQEmuFolder & "logs"
                                                        End If
                                                Else
                                                        Wscript.Echo "ERROR - Could not start world.exe"
                                                End If
                                        Else
                                                Wscript.Echo "ERROR - Could not start minilogin.exe"
                                        End If
                                Else
                                        Wscript.Echo "ERROR - eqlaunch.exe is required for this script and was not found."
                                End If
                        Else
                                Wscript.Echo "ERROR - world.exe is required for this script and was not found."
                        End If
                Else
                        Wscript.Echo "ERROR - MiniLogin.exe is required for this script and was not found."
                End If
        Else
                Wscript.Echo "ERROR - The EQ Emulator Folder does not exist:  " & strPathToEQEmuFolder
        End If
       
        If True = binDoCleanup Then
                strComputer = "."
                Set objWMIService = GetObject("winmgmts:" _
                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                Set colProcess = objWMIService.ExecQuery _
                        ("SELECT * FROM Win32_Process")
                For Each objProcess in colProcess
                        If "zone.exe" = LCase(objProcess.Name) or "world.exe" = LCase(objProcess.Name) or "eqlaunch.exe" = LCase(objProcess.Name) or "minilogin.exe" = LCase(objProcess.Name) Then
                                objProcess.Terminate()
                        End If
                Next
        End If
Else
        Wscript.Echo Wscript.ScriptName & vbcrlf & _
                                vbtab & "by: Knightly" & vbcrlf & _
                                vbtab & "Last Updated: 2007-09-03" & vbcrlf & _
                                vbcrlf & _
                                "Requirements:" & vbtab & "(File)" & vbtab & vbtab & "(Minimum Version)" & vbcrlf & _
                                                vbtab & vbtab & "MiniLogin.exe" & vbtab & vbtab & "0.6.2" & vbcrlf & _
                                                vbtab & vbtab & "World.exe" & vbtab & vbtab & "0.7.0" & vbcrlf & _
                                                vbtab & vbtab & "EQLaunch.exe" & vbtab & vbtab & "0.7.0" & vbcrlf & _
                                vbcrlf & _
                                "This script will start MiniLogin.exe, start World.exe and wait for a connection " & _
                                "to the login server, then start EQLaunch.exe zone.  Finally, it will give you a " & _
                                "dialog box that you can use to stop the server. " &  vbcrlf & _
                                vbcrlf & _
                                "Syntax:" & vbcrlf & _
                                vbtab & vbtab & Wscript.ScriptName & " PathToEQEmuFolder" & vbcrlf & _
                                "Example:" & vbcrlf & _
                                vbtab & vbtab & Wscript.ScriptName & " C:\EQEmu" & vbcrlf
End If

Function ProcessIsRunning(strProcessToCheck)
        ProcessIsRunning = False
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colProcess = objWMIService.ExecQuery _
                ("SELECT * FROM Win32_Process")
        For Each objProcess in colProcess
                If LCase(objProcess.Name) = LCase(strProcessToCheck) Then
                        ProcessIsRunning = True
                        Exit Function
                End If
        Next
End Function



All times are GMT -4. The time now is 06:10 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.