.NET downgrade admin elevation or impersonate as current user when executing specific block of code calling COM+ that requires lower permission

148 views Asked by At

I have a .NET Windows Form application that users run as admin since it requires specific access to files.
The app has been working fine for years but we need to add a feature where users can generate email from inside the application using Microsoft.Office.Interop.Outlook.
As soon as we call "new" on the Outlook object, it blows up with the following error:

System.Runtime.InteropServices.COMException (0x80080005): 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)).

This is because MS Outlook is running without elevated privileges by default and the Windows Form app is running with elevated privileges but COM+ can't handle this setting.

So I need a way to call the .NET Outlook code as the current user but with less elevated privileges.

I have looked at the WindowsIdentity Class but it does not seem to work. I need someway to run a method or block of code as the current user but with less elevated privileges.

1

There are 1 answers

1
Eugene Astafiev On

The app has been working fine for years but we need to add a feature where users can generate email from inside the application using Microsoft.Office.Interop.Outlook.

You need to run your WinForms app without admin privileges if you want to automate Outlook in that case. Or just run Outlook under the same security context with your application. Otherwise, you may consider other technologies for sending email - EWS, Graph API, use the MailMessage Class from the .net BCL and etc.