1

好的,我在 C# 应用程序中使用 Outlook 互操作程序集识别 .PST 文件没有问题。但是,一旦我点击了受密码保护的文件,系统就会提示我输入密码。我们正在我们的组织中禁用 PST 的使用,其中一个步骤是从用户的 Outlook 配置文件中卸载 PST 文件。我需要让这个应用程序静默运行而不提示用户。有任何想法吗?有没有办法在没有 UI 的情况下创建 Outlook.Application 对象,然后尝试在受密码保护的文件上捕获异常?

// create the app and namespace
Application olApp = new Application();                
NameSpace olMAPI = olApp.GetNamespace("MAPI");
// get the storeID of the default inbox
string rootStoreID = olMAPI.GetDefaultFolder(OlDefaultFolders.olFolderInbox).StoreID;
// loop thru each of the folders
foreach (MAPIFolder fo in olMAPI.Folders)
{
    // compare the first 75 chars of the storeid
    // to prevent removing the Inbox folder.
    string s1 = rootStoreID.Substring(1, 75);
    string s2 = fo.StoreID.Substring(1, 75);
    if (s1 != s2)
    {           
        // unload the folder
        olMAPI.RemoveStore(fo);
    }    
}
olApp.Quit();
4

1 回答 1

0

是的,您可以从另一个应用程序自动化 Outlook。NameSpace 对象上有一个Logon方法,因此您可以登录到配置文件,然后您可以做任何您想做的事情。但我认为它会在自动化时再次弹出提示,但是..有一个第三个库可以帮助你做到这一点,就像它通过 mapi 一样。检出兑换库中的profman.dll

于 2010-03-07T11:04:45.753 回答