Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Need Batch/Script file to run program

Posted on 2007-07-21
Medium Priority
Last Modified: 2010-08-05
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.
Question by:Rockit55
  • 2
LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 19541279
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


LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 19541695
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)  :-)


Author Comment

ID: 19543089
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!

LVL 65

Expert Comment

ID: 19543821
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



Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
You may have discovered the 'Compatibility View Settings' workaround for making your SBS 2008 Remote Web Workplace 'connect to a computer' section stops 'working around' after a Windows 10 client upgrade.  That can be fixed so it 'works around' agai…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question