How To Check And Start An Application If It Is Not Running In Windows
Posted by in Tips And Tricks September 15, 2011 1 Comment

I will provide a VB Script that will check and start an application (or process) if it is not running. And I will show How to create a Windows Task Scheduler that automatically calls the VB script every few minutes.

It is applied properly on Windows Vista, Windows 7 or Windows Server 2008. I haven’t tested on Windows XP or Windows Server 2003.

1. VB Script start an application if it is not running

Download the VB Script (Failsafe.vbs) and update strEXEFileName and strEXEFilePath with your application file name and its path.

The VB Script content:

Dim objWMIService, colItems, objItem, strComputer, strFlashEXEFile
Dim count
 
strEXEFileName = "your-application-name.exe"
strEXEFilePath = "D:/path-to-your-app/" & strEXEFileName
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_Process")
 
count = 0
 
For Each objItem In colItems
	If objItem.Name = strEXEFileNameThen
		count = count + 1
	Else
	End If
Next
 
Set objWMIService = Nothing
Set colItems = Nothing
 
If count = 0 Then
 
	Dim oShell
	Set oShell = WScript.CreateObject ("WScript.Shell")
	Return = oShell.run(strEXEFilePath,3, false)
	Set oShell = Nothing
 
End If

2. Create Task Schedule To Run The Script every 10 minutes automatically

Create a new Schedule Task by doing following steps below:

  • 1. Start => All Programs => Accessories => System Tools => Task Scheduler.
  • 2. Click the Action menu, and then click Create Task.
  • 3. In the General tab, type a name for the task and an optional description.
  • 4. Go to Triggers tab then click on New button to create a schedule to run the task.
  • 5. In the New Trigger box, select Daily radio button and check on Repeat task every … option to determine How often we would like to check the app.

    Let’s say Repeat task every 10 minutes:

    Windows Task Schedule Repeat Task Settings

    Windows Task Schedule Repeat Task Settings

    Then click OK to finish this step.

  • 6. Go to Actions tab and click New. In the New Action box, select Start a program in the Action drop down list, and then Browse to the VB Script (Failsafe.vbs) similar to image below:
    Windows Task Schedule Start A Program

    Windows Task Schedule Start A Program

  • 7. Click OK to finish this step.

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com
  • loc h

    Thanks for the code Hoan!

    FYI, if the path of your program has spaces, you need to make it like:

    strEXEFilePath = “”"C:\Program Files (x86)\blah\” & strEXEFileName & “”"”