How to prevent task scheduler from starting a program already running

N

Nick Cumberbatch

I am using Windows XP Professional.

I have setup Task Scheduler to start Microsoft Outlook to run at 7 AM each
day. However since I use the program often, I may sometimes leave it
running overnight. Then in the morning I find two instances of Microsoft
Outlook running, the one that I started originally and the one Task
Scheduler started. How do I resolve this
 
P

Pegasus \(MVP\)

Nick Cumberbatch said:
I am using Windows XP Professional.

I have setup Task Scheduler to start Microsoft Outlook to run at 7 AM each
day. However since I use the program often, I may sometimes leave it
running overnight. Then in the morning I find two instances of Microsoft
Outlook running, the one that I started originally and the one Task
Scheduler started. How do I resolve this

Embed Outlook in a batch file like so:

@echo off
TaskList | find /i "Outlook" || c:\Program . . . . \ outlook.exe
 
N

Nick Cumberbatch

I should have mentioned that my computer knowledge just a little more than
beginner.

Could you kindly interpret this for me in simple instructions

Thanks
 
P

Peter Howarth

Hi,

Pegasus's message, in simple terms:

1) Start notepad (start -> programs -> accessories -> notepad)
2) copy the two lines below (which pegasus provided, except I've filled them
in a bit), into notepad:

@echo off
TaskList | find /i "Outlook" || "c:\Program files\microsoft
office\office10\outlook.exe"

3) In task scheduler, edit the current task (right-click, properties) and
look at the text in the 'run' box - it will look something like the last
half of the line we just copied into notepad. If it is different, then copy
and paste it from the run box into the notepad file. (If you have a
different version of Office to me, it will certainly be different)
4) save the file somewhere as outlook.bat (ensure you select 'All files' in
the 'files of type' option in the save dialog, or your file will be
"outlook.bat.txt" which we don't want)
5) Back in task scheduler, click the browse button and locate the
outlook.bat file you just created.

That should work. (Pegasus, feel free to correct anything if I've missed
something)

Basically, the batch file (outlook.bat) gets a list of currently running
processes (tasklist) and passes it onto the 'find' command which searches
for 'outlook' in that list. If it finds it, then the batch file stops
(because outlook is already running). Otherwise it runs Outlook.

Peter
 
P

Pegasus \(MVP\)

Thanks for expanding my suggestion. There is actually
something I need to add. You recommended to the
OP to save the batch file as "Outlook.bat". This is a
bad idea and it frequently pops up in these newsgroups.
You must never create a batch file under the same name
as an executable. At best you will get a looping batch
file and at worst some totally confusing behaviour. Call
it "c:\Windows\LaunchOutlook.bat" instead.
 
N

Nick Cumberbatch

I tried saving the file in 3 different ways (separately of course)
1) "c:\desktop\outlook.bat"
2) "c:\Windows\LaunchOutlook.bat"
3) "c:\programs\microsoft office\office11\outlook.bat"

Here is what happened:
1) If the program is already running...another instance is not started
2) If the program is not running....it does not start

so the bottom line is...this did not work, unfortunately. I should mention
that at the specified time a small black screen comes up for a few seconds
and disappears. Seems like we have the right idea that needs further
development

I await your responses

Nick
 
P

Pegasus \(MVP\)

Please post the batch file that causes this behaviour.
Do not retype it - just copy & paste it.
 
N

Nick Cumberbatch

Here it is:
@echo off
TaskList | find /i "Outlook" || "c:\Program files\microsoft
office\office11\outlook.exe"

By the way have you tried to re-create this situation
 
P

Pegasus \(MVP\)

The batch file you posted does exactly what it's supposed
to do:
- If Outlook is not active then it will start Outlook.
- If Outlook is active then it won't to anything.

I'm now trying to guess what you're doing on your own PC.
How many lines does your batch file have, 2 or 3?

Let's run a test. Do the following verbatim:
1. Mark and copy the lines between these asterisked lines
(but excluding the asterisks):
****************
@echo off
echo %date% %time% %1 >> c:\test.txt
Tasklist >> c:\test.txt
****************
2. Click Start / Run / notepad c:\test.bat {Enter}
3. Paste the above three lines.
4. Click File/Save, then File/Exit.
5. Kill Outlook if it is active.
6. Click Start / Run / c:\test.bat Outlook is off {OK}
7. Launch Outlook.
8. Click Start / Run / c:\test.bat Outlook is on {OK}
9. Click Start / Run / notepad c:\test.txt {OK}
10. Paste the text into your reply.
 
N

Nick Cumberbatch

01-Sep-06 8:48:25.39 Outlook

Image Name PID Session Name Session# Mem Usage
========================= ====== ================ ======== ============
System Idle Process 0 Console 0 28 K
System 4 Console 0 236 K
smss.exe 1064 Console 0 388 K
csrss.exe 1132 Console 0 4,264 K
winlogon.exe 1156 Console 0 2,740 K
services.exe 1200 Console 0 5,320 K
lsass.exe 1212 Console 0 6,448 K
svchost.exe 1396 Console 0 5,008 K
svchost.exe 1444 Console 0 4,604 K
svchost.exe 1588 Console 0 21,024 K
EvtEng.exe 1652 Console 0 7,840 K
S24EvMon.exe 1692 Console 0 5,588 K
WLKEEPER.exe 1720 Console 0 6,056 K
svchost.exe 1772 Console 0 3,280 K
svchost.exe 2000 Console 0 4,380 K
CCSETMGR.EXE 468 Console 0 3,736 K
CCEVTMGR.EXE 492 Console 0 2,064 K
spoolsv.exe 712 Console 0 6,792 K
svchost.exe 1536 Console 0 3,224 K
NicConfigSvc.exe 1708 Console 0 4,472 K
NPROTECT.EXE 1784 Console 0 4,648 K
RegSrvc.exe 1860 Console 0 2,900 K
NOPDB.exe 356 Console 0 3,004 K
svchost.exe 412 Console 0 6,524 K
symlcsvc.exe 436 Console 0 200 K
wdfmgr.exe 680 Console 0 1,792 K
vsmon.exe 912 Console 0 28,564 K
explorer.exe 1828 Console 0 21,188 K
WFXSVC.EXE 2132 Console 0 1,400 K
WFXMOD32.EXE 2152 Console 0 10,776 K
wmiapsrv.exe 2160 Console 0 4,012 K
xcommsvr.exe 2248 Console 0 3,320 K
ahfp.exe 2296 Console 0 3,684 K
wmiprvse.exe 2356 Console 0 5,140 K
bdss.exe 2488 Console 0 29,568 K
MsgPlus.exe 2612 Console 0 2,328 K
issch.exe 2620 Console 0 1,292 K
ZCfgSvc.exe 2632 Console 0 9,616 K
iFrmewrk.exe 2640 Console 0 12,236 K
hkcmd.exe 2648 Console 0 2,740 K
ezprint.exe 2656 Console 0 7,276 K
tfswctrl.exe 2672 Console 0 3,560 K
igfxsrvc.exe 2680 Console 0 3,376 K
rundll32.exe 2704 Console 0 3,388 K
bdswitch.exe 2724 Console 0 1,908 K
bdnagent.exe 2768 Console 0 960 K
bdmcon.exe 2824 Console 0 1,624 K
acrotray.exe 2876 Console 0 2,680 K
zlclient.exe 2896 Console 0 4,712 K
SynTPEnh.exe 2904 Console 0 4,628 K
jusched.exe 2928 Console 0 2,160 K
stsystra.exe 2944 Console 0 3,896 K
lxcjmon.exe 2976 Console 0 4,836 K
igfxpers.exe 3016 Console 0 2,788 K
quickset.exe 3024 Console 0 6,972 K
CCAPP.EXE 3052 Console 0 6,424 K
DSAgnt.exe 3088 Console 0 3,504 K
YahooMessenger.exe 3124 Console 0 47,392 K
PlaxoHelper.exe 3196 Console 0 2,572 K
livesrv.exe 3260 Console 0 3,664 K
netwaiting.exe 3308 Console 0 4,244 K
vsserv.exe 3412 Console 0 6,924 K
ctfmon.exe 3460 Console 0 3,348 K
lxcjcoms.exe 2012 Console 0 4,692 K
alg.exe 2040 Console 0 3,540 K
Dot1XCfg.exe 1036 Console 0 9,524 K
TosBtMng.exe 544 Console 0 6,204 K
ezi_hnm2.exe 3344 Console 0 1,640 K
ezi_hnm2.exe 1532 Console 0 12,300 K
TosA2dp.exe 2432 Console 0 3,696 K
TosBtHid.exe 3776 Console 0 1,696 K
TosBtHSP.exe 3084 Console 0 4,228 K
TosOBEX.exe 2400 Console 0 6,264 K
TosBtProc.exe 4428 Console 0 3,688 K
msimn.exe 6044 Console 0 60,344 K
cmd.exe 3388 Console 0 1,592 K
tasklist.exe 5352 Console 0 4,524 K
wmiprvse.exe 3256 Console 0 5,652 K
01-Sep-06 8:49:04.15 Outlook

Image Name PID Session Name Session# Mem Usage
========================= ====== ================ ======== ============
System Idle Process 0 Console 0 28 K
System 4 Console 0 236 K
smss.exe 1064 Console 0 388 K
csrss.exe 1132 Console 0 4,324 K
winlogon.exe 1156 Console 0 2,740 K
services.exe 1200 Console 0 5,320 K
lsass.exe 1212 Console 0 6,456 K
svchost.exe 1396 Console 0 5,040 K
svchost.exe 1444 Console 0 4,608 K
svchost.exe 1588 Console 0 21,004 K
EvtEng.exe 1652 Console 0 7,844 K
S24EvMon.exe 1692 Console 0 5,588 K
WLKEEPER.exe 1720 Console 0 6,056 K
svchost.exe 1772 Console 0 3,288 K
svchost.exe 2000 Console 0 4,380 K
CCSETMGR.EXE 468 Console 0 3,736 K
CCEVTMGR.EXE 492 Console 0 2,064 K
spoolsv.exe 712 Console 0 6,800 K
svchost.exe 1536 Console 0 3,224 K
NicConfigSvc.exe 1708 Console 0 4,472 K
NPROTECT.EXE 1784 Console 0 4,648 K
RegSrvc.exe 1860 Console 0 2,900 K
NOPDB.exe 356 Console 0 3,004 K
svchost.exe 412 Console 0 6,524 K
symlcsvc.exe 436 Console 0 200 K
wdfmgr.exe 680 Console 0 1,792 K
vsmon.exe 912 Console 0 28,832 K
explorer.exe 1828 Console 0 21,464 K
WFXSVC.EXE 2132 Console 0 1,400 K
WFXMOD32.EXE 2152 Console 0 10,776 K
wmiapsrv.exe 2160 Console 0 4,012 K
xcommsvr.exe 2248 Console 0 3,320 K
ahfp.exe 2296 Console 0 3,684 K
wmiprvse.exe 2356 Console 0 5,120 K
bdss.exe 2488 Console 0 29,116 K
MsgPlus.exe 2612 Console 0 2,328 K
issch.exe 2620 Console 0 1,292 K
ZCfgSvc.exe 2632 Console 0 9,616 K
iFrmewrk.exe 2640 Console 0 12,236 K
hkcmd.exe 2648 Console 0 2,740 K
ezprint.exe 2656 Console 0 7,288 K
tfswctrl.exe 2672 Console 0 3,560 K
igfxsrvc.exe 2680 Console 0 3,376 K
rundll32.exe 2704 Console 0 3,388 K
bdswitch.exe 2724 Console 0 1,908 K
bdnagent.exe 2768 Console 0 960 K
bdmcon.exe 2824 Console 0 1,684 K
acrotray.exe 2876 Console 0 2,680 K
zlclient.exe 2896 Console 0 4,720 K
SynTPEnh.exe 2904 Console 0 4,628 K
jusched.exe 2928 Console 0 2,160 K
stsystra.exe 2944 Console 0 3,896 K
lxcjmon.exe 2976 Console 0 4,836 K
igfxpers.exe 3016 Console 0 2,788 K
quickset.exe 3024 Console 0 6,972 K
CCAPP.EXE 3052 Console 0 6,424 K
DSAgnt.exe 3088 Console 0 3,504 K
YahooMessenger.exe 3124 Console 0 47,500 K
PlaxoHelper.exe 3196 Console 0 2,572 K
livesrv.exe 3260 Console 0 3,664 K
netwaiting.exe 3308 Console 0 4,244 K
vsserv.exe 3412 Console 0 6,924 K
ctfmon.exe 3460 Console 0 3,352 K
lxcjcoms.exe 2012 Console 0 4,692 K
alg.exe 2040 Console 0 3,540 K
Dot1XCfg.exe 1036 Console 0 9,524 K
TosBtMng.exe 544 Console 0 6,204 K
ezi_hnm2.exe 3344 Console 0 1,640 K
ezi_hnm2.exe 1532 Console 0 12,328 K
TosA2dp.exe 2432 Console 0 3,696 K
TosBtHid.exe 3776 Console 0 1,696 K
TosBtHSP.exe 3084 Console 0 4,228 K
TosOBEX.exe 2400 Console 0 6,264 K
TosBtProc.exe 4428 Console 0 3,688 K
msimn.exe 6044 Console 0 60,372 K
wmiprvse.exe 3256 Console 0 6,028 K
OUTLOOK.EXE 2208 Console 0 18,936 K
WINWORD.EXE 1032 Console 0 19,216 K
cmd.exe 5620 Console 0 1,592 K
tasklist.exe 5624 Console 0 4,532 K
 
P

Pegasus \(MVP\)

Your previous test confirms again that everything is as
it should be. Unfortunately you chose not to answer
my question about the number of lines you have in
your batch file. This means that you need to perform
another test run under tightly controlled conditions. Do
the following verbatim:
1. Mark and copy the three lines between these asterisked lines
(but excluding the asterisks):
****************
@echo off
TaskList | find /i "Outlook" || "c:\Program files\microsoft
office\office10\outlook.exe"
pause
****************
2. Click Start / Run / notepad c:\test2.bat {Enter}
3. Paste the above three lines. If you get four lines,
unwrap the second line. It must start with TaskList
and end with .exe".
4. Click File/Save, then File/Exit.
5. Kill Outlook if it is active.
6. Click Start / Run / c:\test1.bat {OK}. Outlook should start.
7. Launch Outlook (unless it is already active).
8. Click Start / Run / c:\test1.bat {OK}. Nothing should happen.
9. Report any message you see on the screen in Steps 6 and 8.
 
N

Nick Cumberbatch

I NEED SOME CLARIFICATION

Please check your instructions below:
1) Office 10 should read office11
2) you asked me to save the file as test2 but in #2, but in #6 and #8 you
mention test1....please reply

also should i be doing anything in Task Scheduler. Right now the command
line is "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"

should I change that to the batch file you had mentioned originally

I await your response
Thanks
 
P

Pegasus \(MVP\)

The number for Office should reflect the location of
Outlook.exe on your PC. It could be 10 or 11.

Use "c:\test2.bat" consistently, contrary to my previous note.

Save the Task Scheduler until later. Right now you need
to get c:\Test2.bat right.
 
P

Pegasus \(MVP\)

I now have a pretty good idea about what's going on
at your end. However, it's almost half past midnight
where I live. Unless you respond within the next few
minutes, this issue will remain unresolved until sometime later.
 
G

Guest

Pegasus (MVP) said:
I now have a pretty good idea about what's going on
at your end. However, it's almost half past midnight
where I live. Unless you respond within the next few
minutes, this issue will remain unresolved until sometime later.


I did respond to say that everything worked as you described. Outlook started according to #6. In #8, I got a window that as me to press any key to continue
 
P

Pegasus \(MVP\)

started according to #6. In #8, I got a window that as me to press any key
to continue
I never saw your reply.

Your problems arose because you were not scheduling the same
task as the one you discussed in your posts. This will, of course,
create a huge amount of confusion! To conclude the exercise you
must do this:
1. Edit c:\Test2.bat and remove the word "pause". Save and
close the file.
2. Use Explorer to delete c:\Windows\LaunchOutlook.bat if it exists.
3. Use Explorer to move c:\Test2.bat to c:\Windows.
4. Use Explorer to rename c:\Windows\Test2.bat to LaunchOutlook.bat.
5. Delete any pre-existing scheduled task that launches Outlook.
6. Create a new scheduled task. It must invoke c:\Windows\LaunchOutlook.bat.
 
N

Nick Cumberbatch

THANKS VERY MUCH.....IT WORKED

But I have a question. Shouldn't there be a simpler way. I thought that it
should be a basic option in Task scheduler, Windows XP

Once again I thank you for your tenacity in resolving this problem

Nick
 
P

Pegasus \(MVP\)

Thanks for the feedback.

Checking if a certain process is already resident is really
outside the scope for the Task Scheduler. A batch file
like the one you use will handle this requirement easily.
 
N

Nick Cumberbatch

I have noticed that a command window opens when outlook starts. It is not
really a problem but a small annoyance. This windows title is:
C\windows\system32\svchost.exe

Any thoughts on this
 
P

Pegasus \(MVP\)

Instead of launching Outlook directly, launch it like so:

start /b "Outlook" "c:\Program Files . . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top