Jump to content

BUG: Outlook event handler


JasonH

Recommended Posts

Hi,

 

 

 

I have found a problem with the event handler script which shuts down Outlook before a backup. If you enable the script to restart Outlook (Const kRelaunchOutlook = True), the script TRIES to write a dumby file (OutlookInstances.ini) to c:\program files\Dantz\Client. This of course fails because regular users do not have write permission to the program files directory. I have modified my script so that it writes the dumby file where the user has permission to write.

 

 

 

The top of the script also mentions the following:

 

 

 

' Norton's new scriptblocking feature stops a script which tries to

 

' write to the filesystem. As this is the technique we use to indicate

 

' that Outlook was running (and that we need to relaunch it), we have

 

' set the default behavior to not relaunch Outlook after the backup

 

' completes.

 

 

 

I have Norton Corporate Edition 7.61 running and relaunching Outlook works just fine. Who knows, maybe Dantz was just running into the above problem I found.

 

 

 

I have also made some more changes to the script so that the user gets notified that Outlook is going to close down. In fact they have the choice of cancelling the backup of Outlook in the event they are in the middle of something important. I have also added a 15 second delay after the script forces Outlook to close. This is because my laptop users are configured to do a send/recieve on shutdown and I don't want the backup to start before that. At the end of the backup, Outlook restarts and let's the user know the backup is finished just in case Outlook didn't automatically restart.

 

 

 

I am including a copy of my modified script below. BTW, the script works fine with Outlook 2002.

 

 

 

Thanks,

 

Jason

 

 

 

' RetroEventHandler.vbs

 

'

 

' Event handler to quit Microsoft Outlook before backing it up.

 

'

 

' Copyright 2000-2001 Dantz Development Corporation

 

'

 

' ----------------------------------------------------------------------------------

 

' Additions / Modifications made by Jason Hislop - jaalaM Technologies Inc.

 

' Modified QuitOutlook(), OpenSavedOutlook() and declaration of kSavedOutlookFile

 

' ----------------------------------------------------------------------------------

 

 

 

Option Explicit

 

 

 

' To have Microsoft Outlook quit for every Retrospect backup script,

 

' leave kBackupScripts empty. To only quit when specific scripts run,

 

' add the names of the backup scripts to kBackupScripts. Use commas to

 

' delimit the script names, e.g.:

 

' Const kBackupScripts = "Notebook backups,Daily Backup"

 

'

 

Const kBackupScripts = ""

 

 

 

' Norton's new scriptblocking feature stops a script which tries to

 

' write to the filesystem. As this is the technique we use to indicate

 

' that Outlook was running (and that we need to relaunch it), we have

 

' set the default behavior to not relaunch Outlook after the backup

 

' completes. Set kRelaunchOutlook to true below to re-enable this feature.

 

'Const kRelaunchOutlook = False

 

Const kRelaunchOutlook = True

 

 

 

' kSavedOutlookFile is used to record if Outlook was running or not.

 

' Modified by Jason Hislop

 

' - User's can't write to the program files directory so the following statement doesn't work

 

'Const kSavedOutlookFile = "OutlookInstances.ini"

 

Const kSavedOutlookFile = "c:\OutlookInstances.ini"

 

 

 

' HandleEvent handles the different script triggers sent to this file.

 

Call HandleEvent()

 

 

 

'

 

' SaveOutlookState

 

'

 

' Save a file to indicate Outlook was running. We will test for this file's

 

' existence when the backup script ends to decide if we should relaunch Outlook.

 

'

 

Sub SaveOutlookState()

 

Dim fso, ts

 

Const ForWriting = 2

 

 

 

On Error Resume Next

 

Set fso = CreateObject("Scripting.FileSystemObject")

 

Set ts = fso.OpenTextFile(kSavedOutlookFile, ForWriting, True)

 

ts.Close

 

On Error GoTo 0

 

End Sub

 

 

 

 

 

'

 

' OpenSavedOutlook

 

'

 

Sub OpenSavedOutlook()

 

Dim fso

 

Dim outlookObj, myNameSpace, myFolder

 

Const olFolderInbox = 6 ' From Outlook 2000 VB docs

 

 

 

Set fso = CreateObject("Scripting.FileSystemObject")

 

If (fso.FileExists(kSavedOutlookFile)) Then

 

On Error Resume Next

 

fso.DeleteFile(kSavedOutlookFile)

 

Set outlookObj = CreateObject("Outlook.Application")

 

Set myNameSpace = outlookObj.GetNameSpace("MAPI")

 

Set myFolder= myNameSpace.GetDefaultFolder(olFolderInbox)

 

If (outlookObj.Explorers.Count = 0) Then myFolder.Display

 

On Error GoTo 0

 

 

 

' Additions made by Jason Hislop - jaalaM Technologies Inc.

 

' Tell the user when the backup has been completed

 

 

 

Dim WshShell

 

Set WshShell = WScript.CreateObject("WScript.Shell")

 

WshShell.Popup "The backup has finished." & vbCrLf & _

 

"You may relaunch Outlook if it hasn't already been started.", 5, "Retrospect Backup", 64

 

End If

 

End Sub

 

 

 

 

 

'

 

' QuitOutlook

 

' Quit all instances of Microsoft Outlook

 

'

 

' Additions made by Jason Hislop - jaalaM Technologies Inc.

 

' Added the ability to allow the user to not close Outlook.

 

 

 

Sub QuitOutlook()

 

Dim outlookObj, outlookAppNum

 

Dim WshShell

 

Dim choice

 

 

 

Set WshShell = WScript.CreateObject("WScript.Shell")

 

 

 

On Error Resume Next

 

 

 

Set outlookObj = CreateObject("Outlook.Application")

 

If (outlookObj.Explorers.Count >= 1) Then

 

 

 

choice = WshShell.Popup("Outlook will automatically close in 30 seconds to " & _

 

"complete a backup." & vbCrLf & vbCrLf & "When the backup has finished, " & _

 

"Outlook should restart." & vbCrLf & vbCrLf & _

 

"Press Cancel to abort the backup.",30,"Retrospect Backup", 1 + 48)

 

 

 

Select Case choice

 

case 2 WshShell.Popup "The Outlook backup has been cancelled.",5,"Retrospect Backup", 16

 

 

 

case Else

 

 

 

If (kRelaunchOutlook = True) Then SaveOutlookState

 

For outlookAppNum = outlookObj.Explorers.Count To 1 Step -1

 

outlookObj.Explorers.Item(outlookAppNum).Application.Quit

 

Next

 

' Sleep for 15 seconds to allow Outlook to close completely

 

' and do a final send/receive

 

WScript.Sleep(15000)

 

 

 

End Select

 

 

 

End If

 

On Error GoTo 0

 

End Sub

 

 

 

 

 

'

 

' StartSource

 

' Quit all instances of Outlook 2000 before Retrospect does its backup.

 

'

 

Function StartSource(scriptName, sourceName, sourcePath, clientName)

 

If (kBackupScripts = "" or InStr(kBackupScripts, scriptName) <> 0) Then

 

QuitOutlook

 

End If

 

StartSource = False

 

End Function

 

 

 

 

 

'

 

' EndSource

 

' Restart Outlook if it was open before the backup

 

' This will be triggered after any script named "Backup Outlook" runs.

 

'

 

Sub EndSource( _

 

scriptName, _

 

sourceName, _

 

sourcePath, _

 

clientName, _

 

KBBackedUp, _

 

numFiles, _

 

durationInSecs, _

 

backupStartDate, _

 

backupStopDate, _

 

scriptStartDate, _

 

backupSet, _

 

backupAction, _

 

parentVolume, _

 

numErrors, _

 

fatalErrCode, _

 

errMsg)

 

 

 

If (kBackupScripts = "" or InStr(kBackupScripts, scriptName) <> 0) Then

 

If (kRelaunchOutlook = True) Then OpenSavedOutlook

 

End If

 

 

 

End Sub

 

 

 

 

 

'

 

' HandleEvent

 

' Dispatch event to each possible function above.

 

'

 

 

 

Sub HandleEvent()

 

Dim cmdArgs

 

Dim eventMsg

 

Dim argNo

 

Dim result

 

Dim debugArgs

 

Dim WshShell

 

 

 

Set WshShell = WScript.CreateObject("WScript.Shell")

 

Set cmdArgs = WScript.Arguments

 

 

 

If (cmdArgs.Count < 1) Then

 

WshShell.Popup "This Retrospect external script will quit any instances of Microsoft Outlook 2000" & _

 

vbCrLf & "before proceeding with a scripted backup when a Retrospect script named " & "'Backup Outlook'" & " runs." & _

 

vbCrLf & _

 

vbCrLf & "To use this file on the backup computer, move it to Retrospect's directory." & _

 

vbCrLf & "To use this file on a client machine, copy it to the directory containing" & _

 

vbCrLf & "the Retrospect client ('retroclient.exe')."

 

Exit Sub

 

Else

 

eventMsg = cmdArgs(0)

 

End If

 

 

 

' get args for debugging

 

debugArgs = "Arguments:"

 

For argNo = 0 To cmdArgs.Count - 1

 

debugArgs = debugArgs & vbCrlf & FormatNumber(argNo, 0) & ":" & cmdArgs(argNo)

 

Next

 

'WshShell.Popup debugArgs ' Uncomment for debugging

 

 

 

' Handle event

 

result = False

 

Select Case eventMsg

 

Case "StartApp"

 

'StartApp cmdArgs(1), cmdArgs(2) = "true"

 

Case "EndApp"

 

'EndApp DateValue(cmdArgs(1))

 

Case "StartBackupServer"

 

'result = StartBackupServer(cmdArgs(1))

 

Case "StopBackupServer"

 

'StopBackupServer DateValue(cmdArgs(1))

 

Case "StartScript"

 

'result = StartScript(cmdArgs(1), DateValue(cmdArgs(2)))

 

Case "EndScript"

 

'EndScript cmdArgs(1), cmdArgs(2), cmdArgs(3), cmdArgs(4)

 

Case "StartSource"

 

result = StartSource(cmdArgs(1), cmdArgs(2), cmdArgs(3), cmdArgs(4))

 

Case "EndSource"

 

EndSource cmdArgs(1), cmdArgs(2), cmdArgs(3), cmdArgs(4), cmdArgs(5), cmdArgs(6), _

 

cmdArgs(7), cmdArgs(8), cmdArgs(9), cmdArgs(10), cmdArgs(11), _

 

cmdArgs(12), cmdArgs(13), cmdArgs(14), cmdArgs(15), cmdArgs(16)

 

Case "MediaRequest"

 

'result = MediaRequest(cmdArgs(1), cmdArgs(2), cmdArgs(3) = "true", cmdArgs(4))

 

Case "TimedOutMediaRequest"

 

'result = TimedOutMediaRequest(cmdArgs(1), cmdArgs(2), cmdArgs(3), cmdArgs(4))

 

Case "ScriptCheckFailed"

 

'ScriptCheckFailed cmdArgs(1), DateValue(cmdArgs(2)), cmdArgs(3), cmdArgs(4)

 

Case "NextExec"

 

'NextExec cmdArgs(1), cmdArgs(2)

 

Case "StopSched"

 

'result = StopSched(cmdArgs(1), cmdArgs(2))

 

Case "PasswordEntry"

 

'PasswordEntry cmdArgs(1), cmdArgs(2), cmdArgs(3), cmdArgs(4)

 

Case Else

 

MsgBox "Unknown command: " & eventMsg

 

waitForUser = True

 

End Select

 

 

 

If (result = True) Then

 

WScript.Quit(-1)

 

Else

 

WScript.Quit(0)

 

End If

 

End Sub

Link to comment
Share on other sites

  • 1 month later...

Yes, but I like the functionality of this script, which is not in the built-in version. Because some people don't want to get out of Outlook right then, allowing an opt-out is nice. Also because we are experiencing the same kind of flakiness that others have reported: Outlook toolbars, address books, prefs screwed up. A while later, everything is fine again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...