Categories

Links

How to schedule an application to launch at a specified time, but only if the application is not already running?

Published: Dec 13, 2005
Send your feedback

Introduction

With Scheduled Tasks, you can schedule any script, program, or document to run at a time that is most convenient for you. There are situations where you don't want a program to launch, if an instance of the program is already running. See the question below:

I have scheduled Microsoft Outlook to run at these times:

How do I arrange it so that if the program is already running, a second instance of the program will not start. For example if I log on at 5 AM and the program is started. At 6 AM I would not require it to start again since it is already running. How do I accomplish this task?

Resolution

This can very easily be accomplished using Windows Scripting. The following script checks if the application is already running or not, and acts accordingly. If Outlook.exe is not already running, then it's launched. Copy the following lines to Notepad, and save as "msolaunch.vbs" (with double-quotes) to the Desktop. You can then schedule this script to run at a specified time.

'Ramesh Srinivasan - Dec 13, 2005

 

Set WshShell = WScript.CreateObject("WScript.Shell")

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery _

 ("SELECT * FROM Win32_Process WHERE Name = 'outlook.exe'")

If colProcesses.Count = 0 Then

   WshShell.Run chr(34) & _

   "%Programfiles%\Microsoft Office\Office10\Outlook.exe" & Chr(34)

End If

The above code is tailored for Outlook 2002. If you have a different version of Outlook, then the application path varies. Make a note of the default location of Microsoft Outlook executable. Choose your version accordingly:

OL98 and OL2000
%Programfiles%\Microsoft Office\Office\outlook.exe

OL2002
%Programfiles%\Microsoft Office\Office10\Outlook.exe

OL2003
%Programfiles%\Microsoft Office\Office11\Outlook.exe