Jump to content

Recommended Posts

Posted

For reasons I am yet to determine on occasions I get multiple sessions of outlook.exe running under the same logon. Mutiple sessions of outlook.exe can result in a -1 message indicating the code has failed and script is closed. This appears to occur when a script function :) moves an email from one outlook folder to another.

As a remedy I am using this code to eliminate any multiple outlook.exe sessions which has successfuly resolved the issue but not solved why multiple sessions of outlook.exe occur in the first place.

;//Close Multiple Occurances of Outlook [Vista Issue] Leave 1 Running
Func _sStopEmailClient()
    While 1
        $list = ProcessList($DefaultEmail & ".exe")
        $s = $list[0][0]
        ;//Exit if Array = Zero [Not Found]
        If $s = 0 Then ExitLoop
        For $i = 1 to $list[0][0]
            $s = $list[0][0]
            ;//Exit and Leave One Occurance Running
            If $s = 1 Then ExitLoop (2)
            ProcessClose($list[$i][1])
            ExitLoop
        Next
    WEnd
EndFunc   ;==>_sStopEmailClient

Comments are always appreciated Ant..

Posted

It would be more useful to see the code that OPENS Outlook. That is presumably where the problem of multiple instances comes from.

;)

I am not trying to be shy about posting the code:

This is the folder management code:

;//Email Folder Manager [Check that the 'sEmailSMS' Folder in Outlook Exist]
Func _EmailFolderManager($Process)
    _MessageDisplay($sMsgDuration, $DStyleTip, $sMessageHeight, $sMsgTextJust, " CHECKING Email Inbox") ;//Pop-Up Processing Message
    ;//Cleanup any Previous Failed Inbox Process
    If FileExists($sBatchDir & $sInboxBatch) Then
        FileSetAttrib($sBatchDir & $sInboxBatch, "-RS")
        FileDelete($sBatchDir & $sInboxBatch)
    EndIf
    ;//Create the Outlook Object
    $o_Outlook = ObjCreate("Outlook.Application")
    $oNamespace = $o_Outlook.GetNameSpace("MAPI")
    $oInbox = $oNamespace.GetDefaultFolder($olFolderInbox)
    $oFolders = $oInbox.Parent.Folders
    ;//Process SMS Valid Folder
    While 1
        ;//Set Folder Name Valid SMS's;
        ;$oSMSFolder = 0
        Global $oSMSFolder = ""
        For $oFolder In $oFolders
            If String($oFolder.Name) = $sSMSFolder Then
                $oSMSFolder = $oFolder
            EndIf
        Next
        ;//Checks for existing Folder otherwise Creates a new folder;
        If IsObj($oSMSFolder) Then
            If $Process = 0 Then
                MsgBox(262208, $Title, $Title & " Folder '" & $sSMSFolder & "' HAS BEEN CREATED", 30)
            EndIf
            ExitLoop
        ElseIf Not IsObj($oSMSFolder) Then
            $iReturn = MsgBox(262180, $Title, $Title & " CREATE Folder '" & $sSMSFolder & "' ?", $sMenuDuration)
            If $iReturn = 6 Then
                $oSMSFolder = $oFolders.Add($sSMSFolder)
                $Process = 0
                If Not IsObj($oSMSFolder) Then
                    MsgBox(64, $Title, "UNABLE to Create " & $Title & " Folder '" & @CRLF _
                             & $sSMSFolder & "' .", $sMenuDuration)
                    ExitLoop
                EndIf
            Else
                MsgBox(0, $Title, "Folder '" & $sSMSFolder & "' NOT CREATED", $sMenuDuration)
                ExitLoop
            EndIf
        EndIf
    WEnd
    ;//Release the Outlook Object
    $o_Outlook = 0
EndFunc   ;==>_EmailFolderManager

And this is the code for creating the Outlook object

;//Create the Object
        $o_Outlook = ObjCreate("Outlook.Application")
        $oNamespace = $o_Outlook.GetNameSpace("MAPI")
        $oInbox = $oNamespace.GetDefaultFolder($olFolderInbox)
        $oFolders = $oInbox.Parent.Folders
        ;//Count the Number of Emails in the Inbox
        $Items = $oInbox.Items.Count
        ;//Initalise Processed Email Folder [sEmailSMS]
        For $oFolder In $oFolders
            If String($oFolder.Name) = $sSMSFolder Then
                $oSMSFolder = $oFolder
            EndIf
        Next
Posted

Maybe this would get any running instance without creating another:

;//Create the Object
        $o_Outlook = ObjGet("", "Outlook.Application")
        If @error Then $o_Outlook = ObjCreate("Outlook.Application")
        If @error Then
            MsgBox(16, "Error", "Failed to get or create Outlook.Application object")
            Exit
        EndIf

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...