17

I'm trying to get the current running version of Outlook or start up Outlook in case it is not running, but I am having some issues in getting or creating the Outlook Application object in Windows 7. I think it has something to do with the user priviliges that are restrictive in Vista and 7. I am working with Outlook 2010.

edit: These errors only appear if I already have an Outlook 2010 instance started. If Outlook is not started, the application can run smoothly (it can start an Outlook instance by itself).

If anybody can tell me how to correctly get the Outlook Application version, that would be really helpful.

The code I'm running is a long try-catch block that keeps on triggering exceptions:


try
{
  // create an application instance of Outlook
  oApp = new Microsoft.Office.Interop.Outlook.Application();
}
catch(System.Exception ex)
{
  try
  {
     // get Outlook in another way
     oApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
  }
  catch (System.Exception ex2)
  {
     // try some other way to get the object
     oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application;
  }
}

The application throws me the following exceptions:

When I try to create a new Outlook application instance:

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

When I try to get the Outlook app instance:

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

When I try to Create an instance through the Activator

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

Thank you!

Alex
  • 7,432
  • 20
  • 75
  • 118

5 Answers5

32

Apparently these errors were triggered because I was running Outlook and the application on different user permission levels (one of them as administrator and the other one as regular user).

Alex
  • 7,432
  • 20
  • 75
  • 118
  • 3
    Andrei I am also having the same issue. How did you solve it? In my case even if the Outlook is not opened manually it gives this error "Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005." – ANP Oct 13 '11 at 09:28
  • 3
    ANP, from what I remember, this error was triggered because I was running Outlook and the application that was accessing Outlook under different user privileges. For me it was because I was running Visual Studio with admin privileges and was trying to retrieve Outlook, which was started with normal privileges (not as admin). Either that or there was a hanging Outlook process I couldn't access, because it was started by another instance of the application. – Alex Oct 13 '11 at 15:28
  • wow!!! thanks for sharing this. I had a completly different problem with the same error code and this is more than likely the exact problem! – Keng Jan 28 '13 at 19:34
  • 2
    I had this same issue. VS is set to run as an admin. When you Run or Debug your app straight from VS, it inherits the admin permissions. If Outlook is open with normal permissions you get the MK_E_UNVAILABLE exception. I've been able to successfully run similar code either when: 1. Outlook is run with admin permissions 2. Outlook is closed and a new Application is created by the app. Also, you may want to check out the MSDN code for getting the existing outlook application. It is similar to the above code but checks for existing FIRST rather than catching an exception: http://bit.ly/18YZarC – yourbuddypal May 20 '13 at 17:14
4
  1. In start menu select Run
  2. Type dcomcnfg and click OK
  3. Component Services window is opened.
  4. Expand the nodes Component Services -> MyComputer -> DCOM Config .
  5. Right click on the application (Outlook Message Attachment) and select properties.
  6. Click on Identity tab whatever necessary.
  7. Click on “The interactive user" then OK
Moustafa
  • 51
  • 1
2

It is true that if you are running a standalone application from Visual Studio or debugging from Visual Studio which use office products, you should be having same access level for both (Visual Studio and Office Products) and that is one of the reasons why this issue occurs but I am seeing online that so many people have this issue while initializing outlook object in a service. I hope what resolved the issue for me would help others too. Please follow along the steps.

  1. Go to command prompt, type the following and press enter. This opens Component Services:

    mmc comexp.msc /32

enter image description here

enter image description here

  1. Expand the nodes Component Services -> MyComputer -> DCOM Config

  2. Now find out your desired application (In this case, Outlook Message Attachment) and right click on the application (If you follow these steps, this issue related all office applications can be resolved) and select properties.

  3. Go to Identity tab and select The interactive user and press OK. This should resolve your issue.

enter image description here

The interactive user is nothing but the logged on user. When you are trying to access office products through service, the access level has to be same and that is the reason you need to specify proper user. If you want to run the service on a server without logging onto it, you need to make sure that the server has a user account which will be used for running the service as well as running office products as specified in Properties as This user (Please look at the Properties dialog box). If you want to learn about the different types of user accounts mentioned in this dialog box, please refer to the following Microsoft link.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms692541%28v=vs.85%29.aspx

1

It looks as if your Office installation has become corrupted.

Try to repair the installation by rerunning setup as Administrator.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • Does starting Outlook manually work without that a modal dialog is blocking the application? Make sure that you test this with the same user account that your application is using. – Dirk Vollmar Sep 20 '10 at 13:15
  • Outlook can start manually. These errors apparently appear only when Outlook is already previously started manually. – Alex Sep 20 '10 at 14:43
0

In my case it was Visual Studio ran as Administrator causing the issue. When I ran it as normal user I got rid of this error finally.

intersum
  • 596
  • 7
  • 19