簡體   English   中英

Office VSTO加載項可能的權限問題-HRESULT 0x80004004(E_ABORT)

[英]Office VSTO add-in possible permission issues - HRESULT 0x80004004 (E_ABORT)

我們已經開發了一個C#Office VSTO外接程序,可以與正在運行的Outlook實例通信(或啟動一個新實例),並且在嘗試創建Outlook任務或約會時,它在某些客戶PC上顯示出權限問題的跡象。 。

異常消息如下:

操作中止(HRESULT的異常:0x80004004(E_ABORT))

這發生在這里:

Outlook.Account DefaultAccount = null;
Outlook.Application outlookApp = GetOutlookApp();    //returns Application object of running Outlook instance / creates a new instance - it works for them.

DefaultAccount = GetAccountForFolder(outlookApp);    //returns the default account of the user. Tried it with a simple setup, only one account etc. - it works for them
String defaultemailaddress;

//CODE RUNS UNTIL THIS POINT
if (DefaultAccount == null)    //if somehow this would end up NULL, which is not the case, because: see code snippet below!
{
    defaultemailaddress = outlookApp.Session.CurrentUser.AddressEntry.Address;
}
else
{
    defaultemailaddress = DefaultAccount.SmtpAddress;    //this could be the problem, but I can't debug it further, and it works in the code block below, to get the AccountType, so I don't understand why I couldn't get the SmtpAddress without a hard exception
}
//FAILS BEFORE THIS LINE COULD RUN.
String email = "test@emailserver.com";

與用戶聯系后,他們告訴我們,他們在一個非常有限的權限集和網絡下運行。

奇怪的是,此代碼段實際上對他們而言運行順暢,這證明Outlook與其他Office加載項之間的連接正常:

Outlook.Application oApp = GetOutlookApp();
Outlook.Account DefaultAccount = GetAccountForFolder(oApp);
String AccountType = DefaultAccount.AccountType.ToString();

IT部門已經嘗試在受影響的PC上調整Outlook的安全策略。 他們允許程序訪問。

他們無法使用管理員權限來啟動工具,但這不是必須的。 最后三行代碼可以工作(獲得帳戶類型),這一事實證明該應用程序確實可以正確啟動,但是看起來它只能運行某些功能...

我還想指出,他們正在使用Exchange,但顯然他們沒有同步問題(如果這些問題可能會影響任何事情,則...)

編輯:這是GetAccountForFolder的實現,該實現獲取默認的Outlook.Account對象。 我發現這是一個代碼片段,發現它運行良好。

public static Outlook.Account GetAccountForFolder(Outlook.Application outlookApp)
{
    // Obtain the store on which the folder resides.
    Outlook.Store store = outlookApp.Session.DefaultStore;

    // Enumerate the accounts defined for the session.
    foreach (Outlook.Account account in outlookApp.Session.Accounts)
    {
        // Match the DefaultStore.StoreID of the account
        // with the Store.StoreID for the currect folder.
        if (account.DeliveryStore.StoreID == store.StoreID)
        {
            // Return the account whose default delivery store
            // matches the store of the given folder.
            return account;
        }
    }
    // No account matches, so return null.
    return null;
}

問題是您在COM加載項對象中存在爭用條件 您應該人為地延遲您的方法。 簡單地進行重試,直到成功為止,如下所示:

bool isDone = false;
while (!isDone)
{
    try
    {
        // your action with Add-In here...

        isDone = true;
    }
    catch (System.Runtime.InteropServices.COMException exception)
    {
        // small delay
        Thread.Sleep(10);
    }
}

提取帳戶后,您可能需要稍作延遲。

Outlook.Account DefaultAccount = null;
Outlook.Application outlookApp = GetOutlookApp();
DefaultAccount = GetAccountForFolder(outlookApp); 
Thread.Sleep(5000); // a bit of startup grace time.

因此,Interop.Outlook中經常會出現Aborted 0x80004004錯誤,請參閱僅在Outlook打開時才能通過Outlook發送電子郵件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM