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

Need Batch/Script file to run program

We have a small exe program running on a Win2003 server which is necessary for some of our legacy applications to operate.  For some unknown reason, this required exe file stops running.  While we are attempting to discover the reason the program stops, I want to run a simple batch/script file which will: see if the program is running, and if not, run it.
I could set this batch file up as a scheduled task to run every 5 minutes.
  • 2
1 Solution
You can try using the VBS file, which constantly runs, monitoring an EXE process from Task Manager.
To end the script, you need to go to the Task Manager, and end the WScript.exe process.
Just change Notepad.exe to the name of the program executable, and see if it works.

strComputer = "."
Set objShell = WScript.CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

boolStillRunning = True

Do While boolStillRunning = True
      Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
      boolStillRunning = False
      For Each objProcess in colProcess
            If objProcess.Name = "notepad.exe" Then
                  boolStillRunning = True
            End If
      Wscript.Sleep 5000
      If boolStillRunning = False Then
            objShell.Exec "notepad.exe"
            boolStillRunning = True
      End If


Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
If that doesn't work, have you considered running your legacy apps on a virtual server running on top of your SBS?  There's great documentation for it here:  http://sbsurl.com/vs

I've done this a number of times and it usually works so much better to let the legacy apps run on older OS's than new ones.  (Although ideally it's better to dump the legacy apps)  :-)

Rockit55Author Commented:
After replacing "notepad.exe" with the file we need to run and saving the code to a text file with a .vbs extension...it seems to be running flawlessly.
Thanks for the help!

No problem.  I forgot to mention, there is a line in there that says
WScript.Sleep 5000
which makes the script wait only five seconds to check if the program's not running, so if you feel like you want to check only every minute, use
WScript.Sleep 60000


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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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