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?
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.
try this How to: Programmatically Send E-Mail
User contributions licensed under CC BY-SA 3.0