i just can't help myself...
added functionality that makes certain you don't end up running multiple instances of the same script accidentally (very bad things would have happened).
runemu.vbs
Code:
set Shell = CreateObject("WScript.Shell")
' return process object collection where process name starts with procName
function ProcessObjectList(procName)
queryStr = "SELECT * FROM Win32_Process WHERE name LIKE '" & procName & "%'"
set ProcessObjectList = GetObject("Winmgmts:").ExecQuery(queryStr)
end function
' is process running?
function Running(procName)
if ProcessObjectList(procName).Count < 1 then
Running = false
else
Running = true
end if
end function
' start processes if not already running
sub RunServer
for each procName in array("EQEmuLoginServer", "World", "EQLaunch", "UCS")
if not Running(procName) then
runStr = procName & ".exe"
if StrComp("EQLaunch", procName, 1)=0 then
runStr = runStr & " zone"
end if
Shell.Run runStr, 0, false
end if
next
end sub
' exit if this script is already running
set processList = ProcessObjectList("wscript")
if processList.Count > 1 then
foundScript = 0
for each process in processList
if StrComp(process.name, "wscript.exe", 1)=0 then
if InStr(process.CommandLine, WScript.ScriptName) then
foundScript = foundScript+1
end if
end if
if foundScript > 1 then
WScript.Echo WScript.ScriptName & " is already running!"
WScript.Quit
end if
next
end if
set processList = Nothing
' loop forever (30000 millisecond delay)
do while true
RunServer
Wscript.Sleep 30000
loop
this one terminates both the monitoring script and all running emulator executables
stopemu.vbs
Code:
set Shell = CreateObject("WScript.Shell")
' return process object collection where process name starts with procName
function ProcessObjectList(procName)
queryStr = "SELECT * FROM Win32_Process WHERE name LIKE '" & procName & "%'"
set ProcessObjectList = GetObject("Winmgmts:").ExecQuery(queryStr)
end function
' exit if this script is already running
set processList = ProcessObjectList("wscript")
if processList.Count > 1 then
foundScript = 0
for each proc in processList
if StrComp(proc.name, "wscript.exe", 1)=0 then
if InStr(proc.CommandLine, WScript.ScriptName) then
foundScript = foundScript+1
end if
end if
if foundScript > 1 then
WScript.Echo WScript.ScriptName & " is already running!"
WScript.Quit
end if
next
end if
set processList = Nothing
' terminate all instances of emulator monitoring script server processes
for each procName in array("WScript", "EQEmuLoginServer", "World", "EQLaunch", "UCS", "Zone")
for each process in ProcessObjectList(procName)
terminate = true
if StrComp(process.name, "wscript.exe", 1)=0 then
if InStr(process.CommandLine, "runemu.vbs") < 1 then
terminate = false
end if
end if
if terminate then
process.Terminate
end if
next
next