Domanda

Al momento si lavora su un VBScript per automatizzare alcuni dei sporco lavoro PST ingestione che faccio, e ho trovato qualcosa di problematico dopo l'aggiornamento da Outlook 2003-2007.

(ottenuto un upgrade per aggirare un problema RTF Corpo in OL2003 ..)

Anche dopo che si ordina Outlook per chiudere il negozio PST, disconnettersi e poi distruggere l'oggetto (imposta objNS = Nothing, ecc), Outlook si blocca ancora in giro per 1-30 secondi a seconda delle dimensioni dei file PST I' sto lavorando.

posso facilmente aggirare e mettere in un ritardo (Wscript.Sleep (300)), ma trovo questo sporco e non si fidano completamente ... tutte le idee su come ottenere Outlook per chiudere correttamente?

Inoltre ho provato a polling per l'istanza tramite GetObject (), ma sembra che restituisce False anche quando OUTLOOK.EXE è ancora visibile in Task Manager.

Codice sto usando qui di seguito:

Function TestPSTInOutlook(strFileName)
' Open PST in Outlook then closes it, primarily to determine
' if Outlook has any difficulty in processing the PST in the
' first place.  Not interested in corruptions per message, just
' PST-wide (and passwords).

    Const olMailItem = 0
    Const olMSG = 3
    Const olDiscard = 1

    On Error Resume Next
    Dim objOL       ' Outlook.Application   
    Dim objNS       ' Outlook.Namespace
    Dim objFolder   ' Outlook.MAPIFolder
    Dim objIS       ' Outlook.Inspector 
    Dim objMail     ' Outlook.MailItem

    Set objOL = CreateObject("Outlook.Application")
    Set objNS = objOL.GetNamespace("MAPI")

    objNS.Logon
    objNS.AddStore strFileName

    If Err.Number <> 0 Then
        loggit_silent = True
        loggit("TestPSTInOutlook(): failed to open " & strFileName & " for reason: " & Err.Description)
        loggit_silent = False
        TestPSTInOutlook = False
    Else
        Set objFolder = objNS.Folders.GetLast
        objFolder.Name = strFileName

        Set objMail = objOL.CreateItem(olMailItem) 
        Set objIS = objMail.GetInspector 

        objIS.Close (olDiscard) 
        objMail.Close (olDiscard)

        objNS.RemoveStore objFolder
        loggit_silent = True
        loggit("TestPSTInOutlook(): success opening " & strFileName)
        loggit_silent = False
        TestPSTInOutlook = True
    End If

' BUG: Outlook 2007 refuses to shut down when told and takes its time - we have to wait otherwise we error  on trying to move the next PST file ...
' Does not exist in OL2003 but if we roll back then we don't get fixed Unicode PST support and degraded  ingestion performance
' 

    objNS.Logoff 
    objOL.Session.Logoff 
    objOL.Quit 

    Set objIS = Nothing 
    Set objMail = Nothing 
    Set objNS = Nothing 
    Set objOL = Nothing 

    Wscript.sleep(300)
End Function

NB: loggit () è puramente una funzione di registrazione (invia a stdout e ad un debuglog.txt)

È stato utile?

Soluzione

Che dire di una funzione come questa per vedere se outlook.exe è ancora in esecuzione

Function IsRunning(procName)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & procName & "'")
    If colProcesses.Count > 0 Then
        request = True
    Else
        request = False
    End If
    Set colProcesses = Nothing
    Set objWMIService = Nothing
    IsRunning = request
End Function

Poi si può solo eseguire un ciclo finché la funzione restituisce falso Qualcosa di simile a questo

Do While IsRunning("notepad.exe")
Loop
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top