Subscribe | Alerts via Email
View All Quotes
“Perfection is the shortest and surest road to bankruptcy.”
-Unknown
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

©2010 Cal Zant
Sign In
Total Posts: 106
This Year: 5
This Month: 1
This Week: 0
Comments: 2

A recent project forced me to try to use the COM-based Office Interop stuff ... painful.  I found some example code and tried to get it to run, but kept getting a System.UnauthorizedAccessException "Retrieving the COM class factory for component with CLSID ..." exception on this line of code:

ApplicationClass excelApplication = new ApplicationClass();

Retrieving the COM class factory for component with CLSID exception

Although the exception above didn't give me much direction, I was able to uncover more details when I went to view the same error in the computer's event log:

"The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID {00024500-0000-0000-C000-000000000046} to the user DOMAIN\USER SID (S-1-5-21-789336058-854245398-1417001333-2107) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool."

The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID

Turns out you have to configure some COM security stuff on the computer before you can actually make a call like this.  Here is what you have to do to adjust the settings.

  1. Figure out what application the CLSID GUID represents.  To do this you have to look in the registry.  So run "regedit" and go to Computer\HKEY_CLASSES_ROOT\CLSID and find the related CLSID folder.  In my case, the error was related to "Microsoft Office Excel Application."
    Figure out what application the CLSID GUID represents
  2. Open the "Compenent Services" configuration window by running "dcomcnfg".

  3. Find the related app like shown below, and then right-click on it and go to "Properties"
    Find the related application in component services
  4. In the "Properties" window go to the "Security" tab.  Then under "Launch and Activation Permissions" click the "Customize" radio button, then click edit.
    customize the launch and activation permissions
  5. Add the account the code is executing as and give them the appropriate permissions:
    add account code is executing as
  6. Then go back to the "Component Services" configuration window and right-click on "My Computer" and go to "Properties":
    Go to computer properties in Component Services configuration window
  7. Under the "COM Security" tab find the area for "Launch and Activation Permissions" and click the "Edit Default" button.
    Edit default for Launch and Activation Permissions
  8. Add the account and set the permissions like we did in step 5. 

That should be it.  Try the code again and it should run (or at least get you past this particular exception).  So far, my experience with COM is that it is painful and should be avoided at almost any cost.  In my scenario though, it seems to be the only viable option out there, because no 3rd party component has the particular feature I needed ... so sometimes this is unavoidable, and I hope these instructions make it a little less painful for you.

Monday, July 20, 2009 9:16:23 AM (Central Standard Time, UTC-06:00)  #