Condividi tramite


Il metodo OpenSharedItem per Outlook contiene un handle di file sui file .msg firmati

Numero KB originale: 2633737

Sintomi

Il OpenSharedItem metodo nel modello a oggetti per Microsoft Outlook non rilascia l'handle di file di un file .msg fino a quando Outlook non ottiene un certo tempo di inattività.

Causa

Questo comportamento si verifica se il file .msg è firmato o crittografato (messaggi basati su SMIME). Si tratta di una limitazione del modo in cui Outlook gestisce internamente l'elaborazione e gli handle di file dei file .msg basati su SMIME. Outlook esegue una verifica in background della firma nel messaggio e rilascia l'handle del file nel file .msg quando Outlook ottiene un certo tempo di inattività. Il file .msg può essere eliminato solo quando Outlook ha completato tutte le elaborazioni necessarie e ha rilasciato l'handle di file.

È possibile ritardare il tentativo di eliminare il file, anche se non esiste un modo diretto per determinare quando Outlook rilascerà il blocco file.

Risoluzione

Non è previsto alcun cambiamento di questo comportamento.

Ulteriori informazioni

Office Outlook 2007 e Outlook 2010 forniscono il OpenSharedItem metodo per aprire file di appuntamenti iCalendar (.ics), file vCard (.vcf) e file di messaggi di Outlook (.msg). Il tipo di oggetto restituito da questo metodo dipende dal tipo di elemento condiviso aperto.

Nell'esempio di Outlook di Microsoft Visual Basic, Applications Edition (VBA) che segue, il codice apre un file di SignedMessage.msg usando il OpenSharedItem metodo . Il codice tenta quindi di eliminare il file .msg dopo la chiusura dell'elemento di posta. Se il file .msg è firmato o crittografato, il codice causa un errore di autorizzazione negata . Tuttavia, se viene aperto un file .msg non firmato o non crittografato, il codice elimina il file .msg come previsto.

Public Sub TestOpenSharedItem()
    Dim oNamespace As Outlook.NameSpace
    Dim oSharedItem As Outlook.MailItem
    Dim oFolder As Outlook.Folder
    On Error GoTo ErrRoutine

    ' Get a reference to a NameSpace object.
    Set oNamespace = Application.GetNamespace("MAPI")'Open the Signed Message (.msg) file containing the shared item.
    Set oSharedItem = oNamespace.OpenSharedItem("C:\Temp\SignedMessage.msg")'Open the Regular Message (.msg) file containing the shared item.
    'Set oSharedItem = oNamespace.OpenSharedItem("C:\Temp\RegularMessage.msg")

    oSharedItem.Close (olDiscard)
    Set oSharedItem = Nothing

    'Add a reference to Microsoft Scripting Runtime
    Dim oFSO As New FileSystemObject

    ' Try to delete the Signed Message
    oFSO.DeleteFile ("C:\Temp\SignedMessage.msg")'Try to delete the Regular Message
    'oFSO.DeleteFile ("C:\Temp\RegularMessage.msg")

EndRoutine:
    On Error GoTo 0
    Set oSharedItem = Nothing
    Set oFSO = Nothing
    Set oNamespace = Nothing
Exit Sub
ErrRoutine:
Select Case Err.Number
    Case -2147024894 ' &H80070002
        ' Occurs if the specified file or URL could not
        ' be found, or the file or URL cannot be
        ' processed by the OpenSharedItem method.
        MsgBox Err.Description, _
        vbOKOnly, _
        Err.Number & " - " & Err.Source
    Case Else
        ' Any other error that may occur.
        MsgBox Err.Description, _
        vbOKOnly, _
        Err.Number & " - " & Err.Source
End Select
GoTo EndRoutine
End Sub