【问题标题】:Outlook which files are connected pstOutlook 连接了哪些文件 pst
【发布时间】:2020-03-18 10:34:36
【问题描述】:

请告诉我如何从注册表中获取信息,目前已连接的 .pst 文件列表?

示例:已安装 Outlook 2013,存档已连接到它 - archive.pst。

从注册表中,我通过 Powershell 获得了如下附件。

get-item HKCU:\software\Microsoft\Office\15.0\Outlook\Search | select -expandProperty property | where {$_ -match '.pst$'}

显示曾经连接的档案列表:

C: \ users \ user \ Documents \ archive1.pst
C: \ users \ user \ Documents \ archive2.pst
C: \ users \ user \ Documents \ archive.pst

但是archive2.pst和archive1.pst现在没有连接,只有archive.pst连接了。

如果可能,最好在 C# 中提供一个实现示例。

【问题讨论】:

  • 顺便说一句,-match 使用正则表达式,所以你应该转义点:-match '\.pst$'
  • 这样查是真的吗?
  • @Martin 验证值得怀疑。我不知道如何找到准确连接的 pst 文件。

标签: c# powershell outlook pst


【解决方案1】:

以下是三个 Outlook VBA 例程,演示了三种不同的方法来检测哪些存储(PST 文件是一种存储类型)可从 Outlook 访问。

抱歉,它们不是 C#。我目前无权访问 C#。如果没记错的话,一旦连接到 InterOp,C# 看起来与 VBA 语句非常相似。

Sub ListStores1()

  Dim InxStoreCrnt As Integer
  Dim NS As NameSpace
  Dim StoresColl As Folders

  Set NS = Application.GetNamespace("MAPI")
  Set StoresColl = NS.Folders

  For InxStoreCrnt = 1 To StoresColl.Count
    Debug.Print StoresColl(InxStoreCrnt).Name
  Next

End Sub
Sub ListStores2()

 Dim StoresColl As Stores
 Dim StoreCrnt As Store

 Set StoresColl = Session.Stores

 For Each StoreCrnt In StoresColl
   Debug.Print StoreCrnt.DisplayName
 Next

End Sub
Sub ListStores3()

  Dim InxStoreCrnt As Long

  With Application.Session
    For InxStoreCrnt = 1 To .Folders.Count
      Debug.Print .Folders(InxStoreCrnt).Name
    Next
  End With

End Sub

【讨论】:

  • 谢谢你,你的例子帮助很大。
【解决方案2】:

C# 中的解决方案如下。这个解决方案对我有用。

using Outlook = Microsoft.Office.Interop.Outlook;

static int Main(string[] args)
{
Outlook.Application app = null;
Outlook.NameSpace ns = null;
Outlook.Store store = null;
Outlook.Stores stores = null;
app = new Outlook.Application();
ns = app.GetNamespace("MAPI");
stores = ns.Stores;
string storeList = string.Empty;
for (int i = 1; i <= stores.Count; i++)
{
store = stores[i];
    storeList += String.Format("{0} {2}",
        //store.DisplayName,
        store.FilePath,
        (store.IsDataFileStore ? ".pst" : ".ost"),
        Environment.NewLine);
    if (store != null)
        Marshal.ReleaseComObject(store);
}
   Console.WriteLine(storeList);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 2014-07-26
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    相关资源
    最近更新 更多