释放 PST 文件上的文件锁定

Release file lock on PST files

我在 VB 中有两个功能,可用于存档已完成项目的电子邮件。第一个打开我前一年的所有电子邮件存储,或者一次只打开一个。这些 PST 文件存储在 Dropbox 上,因此一旦 Outlook 打开 PST 文件,它就会锁定它们并且不会让 Dropbox 同步文件。现在,我有第三个例程关闭所有打开的 PST 文件,关闭 Outlook 并调用一个批处理文件重新启动 outlook,而不打开 PST 文件,以便 Dropbox 可以完成同步。

Sub OPENALL()
    Application.GetNamespace("MAPI").AddStore "E:12.pst"
    Application.GetNamespace("MAPI").AddStore "E:13.pst"
    Application.GetNamespace("MAPI").AddStore "E:14.pst"
    Application.GetNamespace("MAPI").AddStore "E:15.pst"
    Application.GetNamespace("MAPI").AddStore "E:16.pst"
    Application.GetNamespace("MAPI").AddStore "E:17.pst"
    Application.GetNamespace("MAPI").AddStore "E:18.pst"
    Application.GetNamespace("MAPI").AddStore "E:19.pst"
    Application.GetNamespace("MAPI").AddStore "E:20.pst"
    Application.GetNamespace("MAPI").AddStore "E:21.pst"
End Sub

Sub CLOSEMSGSTORE()
    Dim objStores As Outlook.Stores
    Dim objStore As Outlook.store
    Dim objOutlookFile As Outlook.folder
    Dim i As Integer
 
    'Get All Outlook Files in Your Outlook
    Set objStores = Outlook.Session.Stores
 
    For i = objStores.Count To 1 Step -1
 
        Set objStore = objStores.item(i)
        Set objOutlookFile = objStore.GetRootFolder
 
        'Exclude the Outlook OST File for Exchange mailbox
        If objStore.ExchangeStoreType = olNotExchange Then
           'Close the PST File
           Outlook.Session.RemoveStore objOutlookFile
        End If
    Next
 
    Set objStores = Nothing
    Set objStore = Nothing
    Set objOutlookFile = Nothing
    
    Shell ("C:\Users\csalv\OneDrive\Documents\Computer Tweaks\outrestart.bat")
    Application.Quit
End Sub

有什么方法可以在不关闭 Outlook 的情况下强制释放 PST 文件上的文件锁?谢谢

默认情况下,MSUPST 提供程序会将 PST 文件引用并加载 30 分钟。或者直到 PST 提供程序 dll 本身被卸载(例如,当主机进程终止时)。

您可能想尝试一下 https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/222328

中提到的注册表项

另一种始终有效的解决方案是将您的 PST 处理功能包装到一个不使用 Outlook 对象模型的单独的 exe 中(例如,您可以使用 Redemption (I am its author) and its RDOSession.LogonPstStore 方法打开 PST 文件) 并从您的主要可执行文件启动它。当辅助进程退出时,您的主要可执行文件应该能够操作 PST 文件。