Kill / respawn application automatically every X minutes

Hello everyone,

I have an application that I need to let run in the background to handle some tasks on a Windows Server 2008 machine. The problem is, there are some bugs in the application that cause it to crash/hang between every 60 to 120 minutes. I don't have the source code so I can't really jump in and isolate the problem...

I do need to keep this application up and running in the meantime until I find a replacement, so it looks like my only option would be to:

1. Automatically kill / respawn this program every X minutes (say, every 45 minutes)
2. Catch any apphang/appcrash errors and kill / respawn the program upon detection.

With regards to #2, when an app crashes / hangs... it appears that the process isn't killed. It just gives me an option "Close this program" or "Check for a solution online." Is there a way to avoid this so that when the app crashes or hangs the process is just allowed to die without any user input... this way the solution above can identify a missing process?



Is there a way to do this with a simple windows batch script or maybe some existing 3rd party software? Or should I look into trying to write something in C#?
mcaincAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChrisCommented:
You could use the 'taskkill' command within a batch file as long as you know the image name of the process. The below command would force kill all notepad instances:

Taskkill /f /im notepad.exe

You could then relaunch the application using the 'start' command.

Just stick this in a task scheduled to run every 45 mins.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OriNetworksCommented:
You can register the program as a service then set the properties if the service to restart the program when it crashes.  Here is a short page describing service recovery options.
http://www.itechtalk.com/thread1557.html
mcaincAuthor Commented:
I'm using task scheduler in windows 2008 to execute a bat file now... it appears to work perfectly when double clicking on it or running it from a command prompt... the problem is, when running it with task scheduler all of the processes start, but they are hidden (i.e., no gui is visible). the processes are working however.

is there a way to get around this? i've been fiddling with it for the last 30 minutes and i can't find any options that won't hide the processes in the background

this is what my batch file (respawn.bat) looks like:


taskkill /f /im csat.exe /t

start c:\apps\35\csat.exe
timeout 5 /nobreak
start c:\apps\36\csat.exe
timeout 5 /nobreak
start c:\apps\37\csat.exe

if i double click on respawn.bat, any existing processes are killed, and the 3 processes are restarted properly (gui is visible, etc).

if the scheduler runs respawn.bat, any existing processes are killed, and the 3 processes are stared, however they are not visible...

i need the gui's to be visible when they restart

pulling my hair out over this!
mcaincAuthor Commented:
ah i see... the only way to get it to run visibly is to "run only when user is logged in" otherwise the processes are hidden... makes sense


thanks guys!
mcaincAuthor Commented:
this is what i needed!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.