# Check if a batch is running.



## Kaltiz (Oct 1, 2008)

Im new here and totally new to this forum so sorry if this is wrong area. Anyway i have a game server and people have being crashing it but it does not restart automatically so i have to do it manually all the time and if im not there when some of the players who use my server are they cant play it.

What i need is a batch file or program that will check if another batch file (My server) is running, and if it is not restart it but if it is check again in another 5 minutes. Also sometimes the batch file that runs my server does not close but displays a message droped, a better idea i had that may be possible is to test the connection between me and the server if there is no connection then close the old batch and start a new one,(if my internet is disconnected this wont be a problem because im hosting it from my own computer) if there still is a connection dont do anything and check again in 5 minutes. Now im a total noob to batch files so i have abosulutly no idea how to do this. If anyone knows how or has a way to do this please post it here. 

some imformation you may need:
operating systme: Windows Vista.

thats all, thanks in advanance.


----------



## Codiah (Sep 27, 2008)

This could be a pretty simple solution, but it really depends on how your batch is set up.... most of those files are set up in a way that they don't execute all of the batch information because they hang on whatever file there running at the time... so if your game server is set up they way i think it is really all you have to do is at the end of your batch script, instead of typing EXIT or leaving it open to close itself just retype the path and name of your batch file... 

the way this works is as long as your server is running in the cmd window it will hang on that application, if your server shuts down it will close that program and execute the rest of the original batch file causing it to restart itself... 

obviously there are much better ways of doing this but this one is simple and effective... once again i'm not sure how your batch is set up, so if this doesnt help you, you may need to provide more information, if possible you may want to provide the coding to your batch file so it can be reviewed... it most likely contains private or sensitive information so i would advise not posting it in the main forum here but rather working with someone privately, i'm sure a few of us including myself here wouldn't mind helping out...


----------



## Kaltiz (Oct 1, 2008)

It may not be so simple, it doesnt really start by a batch, its a program that starts up a bat, and i didnt make it so im not sure how can edit this, also sometimes when the server does crash it doesnt close it just says "DROPPED" and sits there until u close it manually and restart server. Is there anyway to edit this .exe so i can do what you have suggested, also i have tried batches that start the server then when that closes it opens the batch again, this does work a little but half the time i have to restart the server manually. 

I think the only ways to fix this problem would be to edit the .exe or make the file i suggested before, pinging the server and if the ping was successfull try again in 5 minutes and if it wasnt start the server exe.


----------



## Codiah (Sep 27, 2008)

well, i can give you the ping example, but without actually seeing the program i can't tell you a better way around this, in my own opinion i would prefer to not ping my own server... but in 5 minute increments it wont be to bad.. anyway... here's a batch file code for ya... replace whats in red..

@ECHO off
TITLE Server Watcher
REM start ping test
:START
ECHO.
ECHO.
ECHO Running Server check...
ECHO %DATE%, %TIME%
ECHO.
ECHO.
ping -n 1 000.000.0.0 | find "unreachable" >nul && GOTO restart 
PING localhost -n 300 >nul
GOTO start
REM restart section..
:restart
taskkill /IM running.exe
start server.exe
PING localhost -n 300 >nul
GOTO START

You will have to replace the ip address to whatever your servers is, and running.exe to the name of the batch file running so it will close, and replace server.exe to the path and name of the file that start the server... but this should work, it will ping your server every 5 minutes and if it doesnt respond it will close the server window and restart it.. dont forget to save it as .bat


----------



## Kaltiz (Oct 1, 2008)

i dont know if u know the game jedi academy but thats the files im using, also i need to add a port as well as a ip where do i the port into code ? because im always going to be connected to myself ....


----------



## Codiah (Sep 27, 2008)

adding a port in a batch file is a simple as putting a space after the ip address and typing the port number... so say you were going to be connecting to your router you would 192.168.1.1, if you wanted that directed at port 23, (telnet normally) you would type 

192.168.1.1 23

there is also another variation

192.168.1.1:23 << i'm not sure however if this one works in a batch file..

so where you put your ip address, just put a space after it and the port number


----------



## Codiah (Sep 27, 2008)

ok so i'm back... i've been running some mock-up test for you, and it doesnt look like this batch file ping idea is going to work...
you cant set the cmd prompt to ping a specific port #, at least not that i myself know of... so this isn't going to work the way you want it to... its only pinging your system.. which means its always going to show online.... so were going to have to figure something else out....


you were saying that the program lanches a batch file, is there anyway you can locate that batch file that it launches and post its contents for me to look at?


----------



## Kaltiz (Oct 1, 2008)

thanks, for your help i went on a holiday and am back now, there is no way i can post the contents because as i said before its a batch files that lanches a exe which for some reason starts up a batch file box starting the server, it would work if the box would close after crashing, sometimes it does but other times it does not, it depends upon which glitched is used, but unforuatly its more commonly the one that doesnt close. if i could edit the exe that starts the server i could have fixed it myself, i fear it is impossible now to fix this problem looking back at the old versions of the server, which started with a batch, they appeared to run a function that was built into the game, i think the only way to fix that is to edit the game, but if not the code that needs to be fix is in the server exe, so just one question, is it possible to open a .exe that is in some near english form which i may be able to understand?


----------



## Codiah (Sep 27, 2008)

depends on how it was put together really.... but if there is readable content inside the .exe.. you would need a hex editor..


----------

