Sunday, February 19, 2006

A script to close outlook for PST file backups


Not everyone can afford an Exchange server, but many still want to backup their data, and the most common problem with backing up PST files is that when they are in use, backup programs cannot back them up, and people very frequently leave Outlook open, causing their data to be at risk. So, I searched the Internet for a script, and I found an article from Bill Stewart at Windows IT Pro. I tried the script, but since it was written for Exchange, it force quit Outlook, which for PST users can cause PST file corruption, exactly the opposite of our intent of protecting the data! I emailed Bill, and within a few hours, he gave me a different script to try that would close Outlook more gracefully. It worked perfect. Thanks, Bill! The code is as follows:


On Error Resume Next
Set Outlook = GetObject(, "Outlook.Application")
If Err = 0 Then
Outlook.Quit()
End If

Just copy the above, and paste it into a file named "closeoutlook.vbs" and you can then schedule that file to run a few minutes prior to the backup job. Now, PST files won't be missed on the backups!