Ask Leo! by Leo A. Notenboom

How do I automatically close a program so that its data can be backed up?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

Home » Windows

Summary: 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

Was this article helpful? «Yes» «No»

Recent Comments
12 Comments

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.

Thx

cu, Fr@

Posted by: Fred Polhout at June 19, 2007 4:16 PM

Hello,

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 ?

Grtz

Posted by: Patrick Versyck at June 21, 2008 6:10 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.

Posted by: Mike at October 24, 2008 8:32 AM

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

Posted by: Scott at March 31, 2009 1:36 PM

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?

Posted by: James Senn at June 11, 2009 9:28 AM

Post a comment on "How do I automatically close a program so that its data can be backed up?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...




Question? Ask Leo!