C#,Vista and Outlook: Runs only without UAC
Hi. I simply try to connect to Outlook from C#:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application app = new Outlook.Application();
But this gives an error, if Outlook is already running (Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.).The error only appears if UAC is enabled.
How can I make my application "UAC"-compatible then? I set the trust-level to "fulltrust", but the error still appears. Any idea?
Added: It works perfectly for a small VB-Script like this, no matter if UAC is enabled or not:
Dim objOutlook
Set objOutlook=GetObject(,"Outlook.Application")
Msgbox "Works"
[829 byte] By [
Wuschba] at [2008-1-9]
I don't think you're going to get around this. Basically, you've designed the app to communicate directly with outlook which is starting to become a big no no.
You might consider a different path such as kicking off that process from within Outlook to drive your application.
Karthikeya Pavan Kumar .B wrote: |
| |
Yes - it's my post as well. I now found that the UAC causes the error.
Chris Lively wrote: |
| I don't think you're going to get around this. Basically, you've designed the app to communicate directly with outlook which is starting to become a big no no. You might consider a different path such as kicking off that process from within Outlook to drive your application. | |
Could you explain this a bit more what you mean by "kicking off that process from within Outlook"? I have a c#-application, and when the user clicks a button, I want to connect to Outlook and read some Mails (just an easy example). So how could I start something here from within Outlook?
Hi Wuschba,
What I mean is that instead of building an external application that opens outlook and reads it's data, you write an Outlook Add-in. This way the code will run within the context of Outlook and therefore has access to its data.
Another option is to have your application communicate with the mail server directly to read and/or process mail. This is easily done and there are plenty of examples out there to do it. If it is an Exchange server then you could even process the contacts and calendar items.
Basically, the issue is that you are creating an application which is trying to read the private data of Outlook and that's not allowed anymore. It is not allowed in order to stop rogue programs from using the computer as a spam bot.
Good luck.