Failing to create an email with outlook interop when outlook has already been opened

1

How do you open an outlook window? I tried the code below but this doesn't work when an instance of outlook is already running -

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

int processCount = processes.Length;
if (processCount != 0)
{
    **outlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;** this is throwing the below error **
}
else
{
    outlookApp = new Microsoft.Office.Interop.Outlook.Application();
}

And I got:

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

Can someone please give an alternate approach or changes to the above code?

c#
wpf
mvvm
outlook
asked on Stack Overflow Nov 6, 2012 by siddu • edited Nov 6, 2012 by mmmmmm

2 Answers

1

Putting in my 2 cents as I'm having the same issue.

It seems that Visual Studio normally being run as an Administrator and Outlook being run with user privileges is the problem.

If close Outlook and run the code it works fine.

If I run the application outside of visual studio (from the Bin folder) with Outlook running it also works fine.

If I run Outlook as administrator and run the application in Visual Studio it works fine.

I haven't yet found a workaround for getting the instance of the Outlook Application class if Outlook is running but on different privileges.

answered on Stack Overflow May 29, 2014 by m.t.bennett
0

User contributions licensed under CC BY-SA 3.0