Helping people with computers... one answer at a time.

It's important to close a program before backing up so that its data files can be backed up. You can close a program automatically or on a schedule.

I have Retrospect on my laptop which has a Maxtor One Touch external drive to do backups. The problem is that if I leave Outlook open the scheduled nightly backup erases the duplicated pst file on the external drive as it cannot copy the open file. Is there some way to run a scheduled job prior to my scheduled backup to close Outlook. I could use "kill" but that is a bit brutal if Outlook happens to be running at the time. I may end up with a corrupt pst file.

I had exactly the same problem. I typically leave Outlook and some other programs running. They lock their files while they're running, so those files can't be backed up or copied.

I had a relatively good solution, but in researching this question I found an even better one.

We're going to need two things: the ability to schedule a program to run at a specific time, and a program that we can run that will close another program.

The first is easy. The "Scheduled Tasks" applet in Control Panel is exactly what we need.

The second took a little hunting, but I found a very useful little freeware utility NirCmd. NirCmd is actually a multi-purpose command line tool ... a Swiss Army Knife of command line tools, as it can do many, many things.

The 'thing' we'll want it to do is close Outlook. After downloading NirCmd, in a Windows command shell, type the following:

nircmd.exe closeprocess outlook.exe

If Outlook was running, it should have been closed. The only exception is if Outlook needed to ask you a question on the way out. For example if you were composing a message, any attempt to close Outlook will result in a message "Do you want to save changes?". Outlook will wait patiently for you to respond, and your backup will once again fail. I'm not aware of a truly safe alternative. NirCmd can, in fact, kill the process instead of just closing it, but as you point out, you run a small risk of PST corruption in that case.

So, to put this all together, we'll use the Scheduled Task Wizard to create the auto-close task.

  • In Control Panel, Scheduled Tasks, hit Add Scheduled Task.

  • Ignore the list, and click on Browse. Locate, and select, nircmd.exe.

  • On the next page of the wizard, give it an appropriate name, and check Daily.

  • On the next page, pick an appropriate time - I would suggest maybe 10 minutes before your backup is scheduled to run.

  • On the next page enter the appropriate user account and password that this program would be run as - typically for this purpose we'd use the same account that you're logged in as.

  • On the last page of the wizard check Open advanced properties for this task..., since we're not quite done.

  • Change the Run entry, adding the parameters closeprocess outlook.exe. It should now look something like this:

    NirCmd Scheduled Job

    (Obviously the location of nircmd.exe will be different for you - you'll typically place nircmd in the Windows directory, or some other directory on your system.)

  • Click OK, and you're done.

You can actually test this new scheduled job by locating it in Control Panel, Scheduled Tasks, right clicking on it, and selecting Run. If Outlook was running, it should close.

If you're a command-line junkie like I am, NirCmd is worth a look. It appears to have many useful features.

Article C2688 - June 13, 2006 « »

Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

June 13, 2006 1:49 PM

Thanks Leo for finding a solution. I lost my hard disk a few months back and was lucky enough to have remembered to manually close Outlook before the scheduled overnight backup. I had a complete backup that was only a few hours old when the hard disk died. More luck than good management. By using this, it removes one of the elements of luck so thank you again.

Alex Lehaen
June 17, 2006 3:36 AM

Hello everybody,

I think i have the solution for the outlook problem. I do this for more then a year now on my servers. I used retrospect together with maxtor one touch to, but it's no stable solution for back-up specialy not for servers because my maxtors (two) made some problems regular.
Now the solution, use SyncBackSe from 2brightspaks, install it on the pc where outlook is instaled and your PST file will be backed up together with your other data . Succes!!

Eli Coten
June 17, 2006 5:57 PM

I think the original question is confused between Outlook Express and Office Outlook.

Outlook Express uses DBX files to store the mail folders - not PST. It comes for free with Internet Explorer 4, and any version of Windows since 98.

Microsoft Office Outlook comes with Microsoft Office which you have to buy. It uses PST files.

Douglas J. Nakakihara
July 12, 2006 9:23 PM

I wrote a little utility to specifically close Microsoft Outlook so you can back up the PST file. It's freeware and you can download at Note that my utility closes Outlook "nicely" and does not kill the process, so the PST file won't get corrupted.

August 31, 2006 3:12 AM

Thx so much for this! It helped me out so much! I didn't have trouble with Outlook but with another program, so thx :D

December 31, 2006 6:51 PM

thanks for the info leo, i tried this, cuz i need to close a program during night, but it just kinda block the program, it doesnt close it, i have to close the process manually cuz the program dont respond anymore, do you know any solution to this?

April 14, 2007 12:31 PM

I noticed no quotations were put into the command in this example. It did not work for me without quotations. Once I put them in, it ran perfectly. I'm using WXPPro. Other than that, thanks.

Fred Polhout
June 19, 2007 4:16 PM

Whe I saw this article, I thought: great, just what I need. But is doesn't work. I get the following log:
"nircmd.job" (nircmd.exe closeprocess outlook.exe) 20-6-2007 1:12:54 ** ERROR **
Unable to start task.
The specific error is:
0x80070005: Access is denied.
Try using the Task page Browse button to locate the application.

Any idea's? I am Administrator.


cu, Fr@

Patrick Versyck
June 21, 2008 6:10 AM


nircmd works perfectly when executed interactively (in batchfile or from commandline) but not when executed in Task Scheduler on my Vista PC

Did I overlook a setting or is Vista a problem ?


October 24, 2008 8:32 AM

After I add closeprocess outlook.exe to the run line, save the task and click run, the status column says could not start. What am I doing wrong? I am admin.

March 31, 2009 1:36 PM

Leos technique worked flawlessly! T Perfect solution for me.
Thanks Leo!

James Senn
June 11, 2009 9:28 AM

I forget to logo off my password protected e-mail program sometimes and then any one can see it, is there a way to have my e-mail program auto close my password when I close my internet explorer page?

May 30, 2010 7:02 PM

I've seen mixed results with using nircmd to close applications gracefully. Outlook, for example, mostly doesn't close on Win 7 although *sometimes* it does. In other words it's not reliable enough.

Looking for other alternatives I quickly wrote a script for the excellent (commercial) Macro Scheduler. However, on a budget a compiled AutoHotKey ( script works just as well.

Here's a simple AutoHotKey script that closes Outlook (use AutoHotKey's Ehk2Exe to convert the script into an executable command which can then be automated to run before the backup process):

; -- begin script --
SetTitleMatchMode RegEx

IfWinExist .*Microsoft\sOutlook
WinClose .*Microsoft\sOutlook
; -- end script --

June 6, 2010 9:41 PM

I have a related issue you may be able to help with. I am running outlook 7 on two computers connected a home wireless network - the main study one has Windows 7 and the kids/kitchen one has xp. I want to be able to log in to outlook from the kitchen one but can't because the outlook.pst is still in use by the one in the study. (see below for message) Is there any way of making one computer automatically log out of outlook when the other computer is trying to open it?
Alternatively, is there a way of automatically logging out of outlook if it hasn't been used in, say, half an hour?
I know I could get in the habit of closing outlook each time but I have three small children and never seem to be able to finish a sentence let alone finish what I need to do on outlook and log out.

the message that appears when I try to open outlook from the kitchen computer is Cannot start microsoft office outlook. Cannot open the outlook window. The set of folders cannot be opened. The file ..... outlook.pst cannot be opened.
All Windows/virus/spyware up to date.

I'm of the opinion that accessing a PST across the network like that is asking for trouble, where trouble means PST corruption and lost contents. It used to be that Outlook wouldn't even let you access a PST across a network.

To answer your question: no, I'm not aware of a solution to automatically or remotely close Outlook or release the PST. With one exception:

Remote desktop. But if you have remote desktop, then I strongly recommend that instead of closing Outlook on the remote machine, you use Outlook on the remote machine. That's essentially what I've always done.

July 19, 2010 11:51 PM

i dont have nircmd.exe on my computer.. help

That's because it's not part of windows. You have to download it by using the link in the article.

July 28, 2010 1:31 AM

Thanks, I managed to close Outlook, but some of our users forget to save and close some emails, so the command will as to save to emails in drafts. I want to automate the "Yes" answer so that it when it asks if I want to save changes, it automatically clicks "yes" and shuts down outlook. I tried this: nricmd.exe closeprocess outlook.exe dlg "" "" click yes. This does not work. Please help

August 13, 2010 6:51 AM

Leo thanks for this tip it was exactly what I was looking for.

August 23, 2010 5:05 PM

This worked very well. I was trying to close down Lotus Sametime Connect, but the closeprocess command didn't seem to be doing anything. I just changed it to killprocess, and Bob is now my uncle.

Marinos Andreou
August 30, 2010 2:07 AM

There is a utility written specifically for closing outlook. It's called Close Outlook 1.0 but I haven't tried it and I don't know if it closes Outlook without killing it.

November 3, 2010 9:15 AM

We have a limited number of floating licences for one of our packages. Most users logon for a few minutes the forget to logout, how can i force a logout after a set period of time.



December 6, 2010 9:38 AM

This is nearly the answer I'm looking for. So I tried to find at NirCMD the solution, but couldnot find it.

Q: How do I automatically start a task after I close a specific program (application)

Because I only start scheduled tasks on time or when I start my PC. But I want a scheduled task when I close a program (application)

I will give a simple example: I will automatically clean my PC and backup some specific files after I close Firefox.

I've not looked into the details much, but the Task Scheduler in Windows 7 has some fairly comprehensive "events" that you can trigger a task from. I'd write a batch file to do the clean up you want and see if the Task Scheduler couldn't be used to automate its run.

Comments on this entry are closed.

If you have a question, start by using the search box up at the top of the page - there's a very good chance that your question has already been answered on Ask Leo!.

If you don't find your answer, head out to to ask your question.