• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

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#?
0
mcainc
Asked:
mcainc
  • 3
1 Solution
 
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.
0
 
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
0
 
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!
0
 
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!
0
 
mcaincAuthor Commented:
this is what i needed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now