C# System.UnauthorizedAccessException:检索 Word Interop 的 COM 类工厂失败,错误为 80070005

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1491123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:03:59  来源:igfitidea点击:

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

c#.netwindows-7

提问by Tomas I

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.

我在 Visual Studio 2008 中的 C# ASP .NET 项目有问题 当我使用 Windows 7 Ultimate (x64) 重新安装我的计算机时,这个问题就开始了。为此,我也在使用 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

System.UnauthorizedAccessException:由于以下错误,检索具有 CLSID {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80070005.at xxx.Utility.WordDocument..ctor(String filePath, HttpServerity) customer_communication.BuCreate_click(Object sender, EventArgs e) in c:\xxx\Website\customer\communication.aspx.cs:line 127

采纳答案by Tomas I

Here is my fix for this problem:

这是我对这个问题的修复:

I'm using Win 7 64bit and Office 2007

我使用的是 Win 7 64 位和 Office 2007

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

运行程序“ dcomcnfg -32”。(如果在 64 位下运行,则找不到 word 和 excel 组件)

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

转到“控制台根目录/组件服务/计算机/我的电脑/DCOM 配置/”查找 Microsoft Word 和 Excel 并选择属性。

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".

转到安全并选择“配置权限”下的“自定义”。(如果需要,您可能还想更改其他权限,但我不需要)添加“IIS_IUSRS”并赋予它“完全控制”。

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

现在转到“身份”并选择“交互式用户”。

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

完成后不要忘记按“确定”。:D

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

我希望这可以帮助您解决您的问题以及其他来到这里并阅读本文的人。

回答by elder_george

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

此错误对应于 .NET System.UnauthorizedAccessException,通常是由您的代码尝试创建的 COM 组件上的访问设置错误引起的。

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.

您可以尝试启动 dcomcnfg 实用程序,转到 DCOM 设置,选择所需的对象并允许为您的 ASP.NET 代码运行的帐户访问它。它应该可以解决您的问题。

回答by Serge S.

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):

您应该为 ASP.NET 进程标识(IIS 5 上的 {MACHINE}\ASPNET 或 IIS 6 上的网络服务)授予对 Word COM 组件的访问权限:

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

“控制面板-管理工具-组件服务-计算机-我的电脑-DCOM配置”

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).

找出“Microsoft Word 文档”,右键单击 - 设置 - 安全选项卡,授予 ASP.NET 进程标识的访问权限(本地和远程)(IIS 5 的“ASPNET”,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.

如果您收到“System.Runtime.InteropServices.COMException (0x800A13E9): 内存不足。立即保存文档”。打开/添加文档时的异常(我自己的经验),只需从 %Temp% 和 \Content.Word 文件夹中删除临时文件。

回答by sliderhouserules

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:

这个对我来说很棘手,也许我的 Windows mojo 技能低于标准。但是我无法让组件服务在 Windows Server 2008 上以 32 位模式运行。希望这可以帮助其他有同样问题的人:

  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.
  1. 通过前面提到的任何一种方法(运行框或管理工具)运行组件服务;关闭这个程序
  2. 将“C:\Windows\System32\mmc.exe”/32 粘贴到运行框中并按 Enter(在任务管理器中验证您是否看到 mmc.exe *32)
  3. 转到文件,您应该会在列表中看到 comexp.msc(因为第 1 步),选择它,它将在您的 32 位模式 MMC 控制台中打开组件服务。

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.

编辑:为了完整起见,为了让 Word Interop 在 Windows Server 2008 上工作,我还必须按照本答案中的概述创建桌面文件夹。

回答by Krissce

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

修复 Tomas 的答案,Windows Server 2k8 x64 上的正确命令是:“dcomcnfg /32”(斜杠而不是 -)

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.

此外,我必须通过添加具有午餐和激活权限、访问权限和配置权限的完全权限的 IIS_IUSRS 来自定义所有安全选项。以及身份选项卡中的交互式用户。然后它对我有用。

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

我在 Word 2010 打开文档文件时遇到了这个问题,我不得不为 Microsoft Word 97-2003 文档属性设置它。

回答by Michael Paulukonis

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

启动dcomcnfg -32dcomcnfg /32两者都未能在列表中显示目标应用程序 (Microsoft Excel)。

But my following the directions @ How to make IIS7 play nice with Office Interop, in particular, the note about launching mmc -32and 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).

但是我按照@How to make IIS7 play nice with Office Interop的指示,特别是关于mmc -32在组件服务管理单元中启动和手动添加的说明,我能够让它出现。(注意:虽然链接谈到 IIS7,但我的问题是 Windows 服务)。

  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!
  1. 开始 > 运行 > dcomcnfg(或“mmc -32”,如果在步骤 3 下找不到应用程序,则手动添加组件服务管理单元)
  2. 导航到组件服务 > 计算机 > 我的电脑 > DCOM 配置
  3. 找到给您带来麻烦的 MS 应用程序(例如:Excel 的“Microsoft Excel 应用程序”或 Word 的“Microsoft Word 97 – 2003 文档”)
  4. 右键单击 > 属性
  5. 在安全选项卡上:在启动和激活权限下选择自定义,然后单击编辑...
  6. 添加站点运行的帐户(例如:网络服务)并分配本地启动和本地激活权限
  7. 瞧!

回答by José Ramón Pérez Rubio

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.

我遇到了同样的问题,最后是因为我的用户没有运行“远程过程调用(RPC)”服务的权限。在控制面板的管理工具中,我查找了该服务,并在登录中单击了“本地系统帐户”,然后重新启动了系统并解决了问题。

回答by gyosifov

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".
  1. 在命令行中输入 DCOMCNFG
  2. 组件服务 -> 计算机 -> 我的电脑 -> DCOM 配置
  3. 找到“Microsoft Word 97 - 2003 文档”(如果没有,请检查您的 Word 是否也是 64 位)
  4. 右键单击-> 属性
  5. 转到选项卡安全性并编辑“自定义”单选按钮,以便 IIS_IUSRS 可以拥有启动和访问权限
  6. 转到 Tab Identity 并选择“交互式用户”
  7. 应用更改并重试
  8. 如果这一切都失败了,请转到“常规”选项卡,然后在“身份验证级别”下拉列表中选择“无”。

回答by Mahdi

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:

我测试了上述所有方法,这些方法也标记为答案,但在 Windows 服务器中,当用户不活动或注销时,获取访问异常。所以:

  1. I created a user on localcomputer and add it to two group: IIS_USERand 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_USERand also Application-identity user (IIS APPPool\[Name]) to all three section on security section and make the full permission as possible. See it here
  1. 我在本地计算机上创建了一个用户并将其添加到两个组中: IIS_USERAdministrator
  2. 组件服务 -> 计算机 -> 我的电脑 -> DCOM 配置
  3. 在 com+ 对象中,我更改为与该用户一起运行 Microsoft Word 97 – 2003 文档组件。 看这里
  4. 还将IIS_USER和应用程序身份用户(IIS APPool\[Name])添加到安全部分的所有三个部分,并尽可能获得完全权限。 看这里

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.

office 将使用您在第一步创建的用户的设置运行,因此如果您更改此用户的任何设置。120% 工作没有问题。尝试了 3 个不同的服务器。

回答by Ran Ray Alcantara

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.

转到注册表HKCR>TypeLib>{00020905-0000-0000-C000-000000000046}>8.7>0,然后删除文件夹“ win32”,这是因为 Word COM Class 错误。

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.

转到注册表HKCR>TypeLib>{00020813-0000-0000-C000-000000000046}>1.9>0,然后删除文件夹“ win32”,这是因为 Excel COM Class 错误。

Try that method that method fixed my problem.

试试那个方法,那个方法解决了我的问题。