Hi,

Outlook 2003
Office Communicator 2007

I need to programmatically shutdown Outlook and Office Communicator in
order to backup my email (outlook.ost). I would then like to restart
both after the backup has occurred.



After some googling, here are my scripts:

Shutdown_Outlook.vbs:

' *** This script programmatically shuts down Outlook so nightly
backup of email can occur
' *** See http://www.pcreview.co.uk/forums/thread-114614.php

Set oApp = GetObject(, "Outlook.Application")
If oApp Is Nothing Then
'no need to do anything, Application is not running
Else
'Application running
oApp.Session.Logoff
oApp.Quit
End If
Set oApp = Nothing

WScript.Sleep 5000

Shutdown_Outlook_2.vbs (version 2, "terminate" seems a bit harsh):

' *** Another shutdown outlook approach

set wmi = GetObject("winmgmts:")
wql = "select * from win32_process where name='outlook.exe'"
set result = wmi.ExecQuery(wql)
for each instance in result
instance.Terminate(0)
next

My current version is the first one. I don't like the error message
if Outlook is not in fact running, but I can call the script with:

cscript //b Shutdown_Outlook.vbs

to suppress the error message. No harm, no foul.

If I can get reassurance that instance.Terminate(0) won't cause
problems when shutting down Outlook, I might consider that approach,
as it does a better job of detecting if Outlook is really running.

Shutdown_Communicator.vbs:

Set oApp = GetObject(, "Communicator.Application")
If oApp Is Nothing Then
'no need to do anything, Application is not running
Else
'Application running
oApp.Quit
End If
Set oApp = Nothing

WScript.Sleep 5000

Start_Outlook.vbs:

' *** This script programmatically starts Outlook

Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "Outlook"


My questions:

1. The Shutdown_Communicator script doesn't work. Since Communicator
also locks outlook.ost, I need to shut both down to do the backup.

2. Is there a better approach to Start_Outlook.vbs? If I run the
script repeatedly, I get multiple instances of Outlook running. I'd
prefer to just have the one instance, the same as when I click the
Outlook icon repeatedly.

3. My default Outlook session also opens a local archive.pst file.
This PST file has a password associated with it. When I run
Start_Outlook, Outlook starts, then the password dialog displays for
the archive pst file. When I run Shutdown_Outlook, Outlook shuts
down, but the password dialog remains. If I click Cancel (or Ok) in
that dialog, I get a crash dialog in Outlook. This is a bug in
Outlook. I suppose I can live with this, but this will happen each
weekend when the backup occurs, and I'm not there to enter the
password in the dialog window. Any thoughts?

I'm happy to also code these scripts in Windows PowerShell. I hope
this cross-posting is OK, apologies if not.

Thanks,
Scott