System.UnauthorizedAccessException: Retrieving the COM class factory for Word Interop fails with error 80070005

一个人想着一个人 提交于 2019-12-17 05:53:33

问题


I have a problem with a C# ASP .NET project in Visual Studio 2008 This problem started when I reinstalled my computer with Windows 7 Ultimate (x64). To this I'm also using Office 2007.

The error message I'm getting is:

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005. at xxx.Utility.WordDocument..ctor(String filePath, HttpServerUtility util) at customer_communication.BuCreate_click(Object sender, EventArgs e) in c:\xxx\Website\customer\communication.aspx.cs:line 127


回答1:


Here is my fix for this problem:

I'm using Win 7 64bit and Office 2007

Run program "dcomcnfg -32". ( You cant find the word and excel components if it runs under 64bit)

Go to "Console Root/Component Services/Computer/My Computer/DCOM Config/" Look up Microsoft Word and Excel and choose properties.

Go to Security and select "Customize" under "Configuration Permissions. (If needed you might want to change the other permissions as well, but I didn't need to) Add "IIS_IUSRS" and give it "Full Control".

Now go to "Identity" and select "The interactive user".

Do not forget to press "OK" when done. :D

I Hope this helps you with your problem and also the rest who gets here and read this.




回答2:


You should grant an access to Word COM component for ASP.NET process identity ({MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6):

"Control Panel - Administrative Tools - Component Services - Computers - My Computer - DCOM Config"

Find out "Microsoft Word Document", right click - Settings - Security Tab, grant access (local and remote) for ASP.NET process identity ("ASPNET" for IIS 5, "Network Service" for IIS 6).


If then you get an "System.Runtime.InteropServices.COMException (0x800A13E9): There is insufficient memory. Save the document now." exception when open/add document (my own expirience), just delete temporary files from %Temp% and \Content.Word folders.




回答3:


This one was sticky for me to figure out, maybe my Windows mojo skills are just sub-par. But I could not get Component Services to run in 32 bit mode on Windows Server 2008. Hopefully this can help someone else with the same problem:

  1. Run Component Services by either method previously mentioned (Run box or Administrative Tools); close this program
  2. Paste "C:\Windows\System32\mmc.exe" /32 into the Run box and hit Enter (verify in Task Manager that you see mmc.exe *32)
  3. Go to File and you should see comexp.msc in the list (because of step 1), select it and it'll open Component Services in your 32 bit mode MMC console.

EDIT: just for completeness sake, in order to get Word Interop working on Windows Server 2008 I also had to create the Desktop folder as outlined in this answer.




回答4:


launching dcomcnfg -32 or dcomcnfg /32 both failed to show the target app (Microsoft Excel) in the list.

But my following the directions @ How to make IIS7 play nice with Office Interop, in particular, the note about launching mmc -32 and manually adding in the Component Services snap-in, I was able to get it to appear. (NOTE: although the link talks about IIS7, my issue was with a Windows service).

  1. Start > Run > dcomcnfg (or “mmc -32″ and then add the Component Services snap-in manually if you can’t find the app under step 3)
  2. Navigate to Component Services > Computers > My Computer > DCOM Config
  3. Locate the MS application giving you trouble (eg: “Microsoft Excel Application” for Excel or “Microsoft Word 97 – 2003 Document” for Word)
  4. Right click > Properties
  5. On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
  6. Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
  7. Voila!



回答5:


This worked for me:

  1. In the command line put DCOMCNFG
  2. Component Services -> Computers -> My Computer -> DCOM Config
  3. Find "Microsoft Word 97 - 2003 Document" (If it is missing check if your Word is also 64 bit)
  4. Right click -> Properties
  5. Go To Tab Security and Edit the "Customize" radio buttons so that IIS_IUSRS could have rights for launch and access
  6. Go to Tab Identity and choose "The interactive user"
  7. Apply changes and try again
  8. If all this fails, go also to tab "General" and in "Authentication Level" drop down choose "None".



回答6:


Fix to Tomas answer, correct command on Windows Server 2k8 x64 is: "dcomcnfg /32" (slash instead of -)

Also I had to customize all security options by adding IIS_IUSRS with full rights to Lunch and Activation Permissions, Access Permissions and Configuration Permissions. And Interactive user in Identity tab as well. Then it worked for me.

I had this problem with Word 2010 opening doc files and I had to set it for Microsoft Word 97-2003 Document Properties.




回答7:


This error corresponds to .NET System.UnauthorizedAccessException and is usually caused by wrong settings for access on COM component your code tries to create.

You may try to start dcomcnfg utility, go to DCOM settings, select required object and allow access to it for the account your ASP.NET code runs under. It should solve your problem.




回答8:


I had the same problem, finally was because my user didn't have permission to run the service "Remote Procedure Call(RPC)". In control panel, Administrative tools, I looked for that service and in Log On I clicked in "Local System Account", I restarted the system and problem solved.




回答9:


I test all above methods that also marked as answer but in windows server when user is not active or logoff, get access exception. so:

  1. I created a user on local computer and add it to two group: IIS_USER and Administrator
  2. Component Services -> Computers -> My Computer -> DCOM Config
  3. In com+ object i change to run Microsoft Word 97 – 2003 Document component with this user. See it here
  4. also add IIS_USER and also Application-identity user (IIS APPPool\[Name]) to all three section on security section and make the full permission as possible. See it here

office will run with settings from user that you create in first step, so if you change any setting with this user. 120% Working with no problem. tried over 3 different server.




回答10:


Go to registry HKCR>TypeLib>{00020905-0000-0000-C000-000000000046}>8.7>0, then delete the folder "win32" this is for Word COM Class error.

Go to registry HKCR>TypeLib>{00020813-0000-0000-C000-000000000046}>1.9>0, then delete the folder "win32" this is for Excel COM Class error.

Try that method that method fixed my problem.



来源:https://stackoverflow.com/questions/1491123/system-unauthorizedaccessexception-retrieving-the-com-class-factory-for-word-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!