none
Failing to create an email with outlook interop when outlook has been opened by another user account RRS feed

  • Question

  • Hello

    I have an addin that customizes the excel ribbon. I added a button so that when the user clicks it, a new outlook message windows pops up with some default information on the email body, CCs, etc.

    The problem is that if outlook is already running and it's running under another user account different from the one that was used to open excel (e.g. after opening excel i open outlook with shift + right click and then "Run As..."); i get an exception upon instantiating the outlook interop object:

    Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

    The exception message reads:


    Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

    What can i do to prevent this issue from happening?


    Thanks

    Tuesday, July 19, 2011 8:30 PM

Answers

  • Not using Outlook, no. Outlook can only run one session at a time and if it's running a session under a certain logon it can't then be logged into from a different logon. An alternative is to use a different machine if you don't need to log into that same Outlook session.
     
    Other than that you might be able to use Redemption (www.dimastr.com/redemption) or Extended MAPI (C++ or Delphi/Pascal only, long learning curve). I've used Redemption to log into different malboxes as long as the permissions are there to allow it. For example, I can log into Mailbox A and if that logon has permissions on Mailbox B and C I can then log into B and C in succession as needed.
     
    That of course would only work with Exchange mailboxes. A non-Exchange profile locks the PST file exclusively so you couldn't do anything with a PST file profile.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:ec6c647d-c16f-4a3c-ab47-956a323e83b6...

    Hi Ken

     

    That is not a restriction i can impose the users, is there any other way?


    Ken Slovak MVP - Outlook
    • Marked as answer by wildarmss Monday, July 25, 2011 2:37 PM
    Friday, July 22, 2011 3:12 PM

All replies

  • In that situation I would test first for an existing Outlook process running and hook into it if it is running. If it's not running then I'd use new to create an Outlook session. There can only be one Outlook session running at a time.
     
    This sort of code will do the trick for you I think:
     

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

    int collCount = processes.Length;

    if (collCount != 0)

    {

    // Outlook already running, hook into the Outlook instance

    outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    }

    An else there would create a new Outlook.Application object.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:870d6093-a7fb-4431-a38f-1896ce4cf963...

    Hello

    I have an addin that customizes the excel ribbon. I added a button so that when the user clicks it, a new outlook message windows pops up with some default information on the email body, CCs, etc.

    The problem is that if outlook is already running and it's running under another user account different from the one that was used to open excel (e.g. after opening excel i open outlook with shift + right click and then "Run As..."); i get an exception upon instantiating the outlook interop object:

    Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

    The exception message reads:


    Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

    What can i do to prevent this issue from happening?


    Thanks


    Ken Slovak MVP - Outlook
    Wednesday, July 20, 2011 1:27 PM
  • Hello Ken

     

    "processes.Length" returns a value of 1, so i tried calling "outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;" as you suggested, but it now throws the following exception:

    Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

     

    Any suggestion?


    Thanks

     


    Thursday, July 21, 2011 2:25 PM
  • I don't know why you're getting that error.
     
    Does it happen if you use the same user identity to start Outlook and then run the code that tries to grab the Outlook instance?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:aba04199-ad59-4bb9-b4da-830fc3d8af24...

    Hello Ken

     

    "processes.Length" returns a value of 1, so i tried calling "outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;" as you suggested, but it now throws the following exception:

    Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

     

    Any suggestion?


    Thanks

     



    Ken Slovak MVP - Outlook
    Thursday, July 21, 2011 3:27 PM
  • Hello Ken

    This doesn't happen when the same user starting outlook is the same one running the other application. It only happens when the account used for each program is different.

    Thursday, July 21, 2011 3:31 PM
  • I think they're going to have to run under the same logons.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:29796c18-1507-4d4a-8234-b962ab4695ff...

    Hello Ken

    This doesn't happen when the same user starting outlook is the same one running the other application. It only happens when the account used for each program is different.


    Ken Slovak MVP - Outlook
    Thursday, July 21, 2011 5:28 PM
  • Hi Ken

     

    That is not a restriction i can impose the users, is there any other way?

    Thursday, July 21, 2011 7:38 PM
  • Not using Outlook, no. Outlook can only run one session at a time and if it's running a session under a certain logon it can't then be logged into from a different logon. An alternative is to use a different machine if you don't need to log into that same Outlook session.
     
    Other than that you might be able to use Redemption (www.dimastr.com/redemption) or Extended MAPI (C++ or Delphi/Pascal only, long learning curve). I've used Redemption to log into different malboxes as long as the permissions are there to allow it. For example, I can log into Mailbox A and if that logon has permissions on Mailbox B and C I can then log into B and C in succession as needed.
     
    That of course would only work with Exchange mailboxes. A non-Exchange profile locks the PST file exclusively so you couldn't do anything with a PST file profile.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:ec6c647d-c16f-4a3c-ab47-956a323e83b6...

    Hi Ken

     

    That is not a restriction i can impose the users, is there any other way?


    Ken Slovak MVP - Outlook
    • Marked as answer by wildarmss Monday, July 25, 2011 2:37 PM
    Friday, July 22, 2011 3:12 PM
  • I am also getting the same error and it is using the same login. I run the app and as long as outlook is not running it works, I then leave the app and do not close outlook and rerun (for testing). The code sees the outlook process so it calls the marshal.GetActiveObject that the app created just a minute before and we get the error Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)).

    One thing I have noticed is that outlook does not seem to ever get put in the rot (running objects table) even though i see the process.

    Windows 7, office 2010, c# 2010

    Friday, July 22, 2011 3:24 PM
  • Hi,
     
    The only times I've seen that problem with code I've written or had to debug was when one of the running applications that started an Outlook instance did so at a different permissions level than the other application.
     
    For example if application A runs as admin and starts Outlook using asInvoker then Outlook will be started as admin and other applications that are running at other levels won't be able to instantiate an Outlook.Application instance.
     
    Other than that about the only thing I can suggest would be to open a support incident with MS. If it's a bug it won't cost you, if it isn't you'd be charged for the support incident unless you have an MSDN subscription or other venue where you have support incidents available to you.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Jeff Langley" <=?utf-8?B?SmVmZiBMYW5nbGV5?=> wrote in message news:f896f733-c3c9-4ec9-8b38-48b7b7fffbcc...

    I am also getting the same error and it is using the same login. I run the app and as long as outlook is not running it works, I then leave the app and do not close outlook and rerun (for testing). The code sees the outlook process so it calls the marshal.GetActiveObject that the app created just a minute before and we get the error Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)).

    One thing I have noticed is that outlook does not seem to ever get put in the rot (running objects table) even though i see the process.

    Windows 7, office 2010, c# 2010


    Ken Slovak MVP - Outlook
    Monday, July 25, 2011 2:30 PM
  • Not using Outlook, no. Outlook can only run one session at a time and if it's running a session under a certain logon it can't then be logged into from a different logon. An alternative is to use a different machine if you don't need to log into that same Outlook session.
      
    Other than that you might be able to use Redemption (www.dimastr.com/redemption) or Extended MAPI (C++ or Delphi/Pascal only, long learning curve). I've used Redemption to log into different malboxes as long as the permissions are there to allow it. For example, I can log into Mailbox A and if that logon has permissions on Mailbox B and C I can then log into B and C in succession as needed.
     
    That of course would only work with Exchange mailboxes. A non-Exchange profile locks the PST file exclusively so you couldn't do anything with a PST file profile.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "wildarmss" <=?utf-8?B?d2lsZGFybXNz?=> wrote in message news:ec6c647d-c16f-4a3c-ab47-956a323e83b6...

    Hi Ken

     

    That is not a restriction i can impose the users, is there any other way?


    Ken Slovak MVP - Outlook
    I've discussed this with the client and it seems it will be ok just to let the users know when this is happening. Thanks a lot for all the information you provided!
    Monday, July 25, 2011 2:37 PM
  • This same error was happening to me.  The problem was because I was running Visual Studio as an Administrator.  Changing Outlook to run as admin, or changing VS to not run as admin fixed the problem.
    • Proposed as answer by jovaldeze Monday, July 7, 2014 2:01 PM
    • Unproposed as answer by jovaldeze Monday, July 7, 2014 2:01 PM
    • Proposed as answer by jardous Friday, September 12, 2014 8:21 PM
    Wednesday, April 3, 2013 7:18 PM
  • Ditto, I had exactly the same problem and my issue was because VS was running as admin.

    Eric Jorgensen http://www.ericjorgensen.com

    Saturday, February 7, 2015 11:25 PM
  • Thank you, Gary!  I thought I had introduced a new bug into my code today until I stumbled across your answer.  It was because I was debugging in Visual Studio running in Administrator mode.  I don't quite understand why the Office COM API's don't want to instantiate when you have admin priveleges, but I digress.  Thanks again.
    Friday, July 29, 2016 5:55 PM
  • Ken, Thanks, trying to instantiate a new Outlook application object yielded the 'COE_E_SERVER_EXEC_FAILURE' for me, so I took your advice and Marshaled a reference.
    Thursday, March 7, 2019 12:12 AM