生成 Word 文档时检索组件错误的 COM 类工厂

发布于 2024-07-29 04:29:49 字数 1086 浏览 4 评论 0原文

我正在尝试使用以下代码从 VB.NET 编辑 Word 文档:

如何从 Visual Basic .NET 自动执行 Word 创建新文档 http://support.microsoft.com/kb/316383

它在我的机器上运行良好,但是当我发布到服务器时收到以下错误。

检索 COM 类工厂 具有 CLSID 的组件 {000209FF-0000-0000-C000-000000000046} 由于以下错误而失败: 80070005。

描述:在执行期间发生未处理的异常 执行当前的网络请求。 请查看堆栈跟踪以了解更多信息 有关错误及其位置的信息 它起源于代码。

异常详细信息: System.UnauthorizedAccessException: 检索 COM 类工厂 具有 CLSID 的组件 {000209FF-0000-0000-C000-000000000046} 由于以下错误而失败: 80070005。

当我尝试

 Dim oWord As New Word.Application

使用 Visual Studio 2008 和 VB.NET 3.5 创建 Word 应用程序对象时,实际发生错误。 我引用了“Microsoft Word 10.0 对象库”,并在 bin 目录中看到了 Interop.Word.dll 文件。

在开发计算机和 Windows Server 2003 上使用 MS Office 2003

对 .NET 来说还是个新手,对窗口服务器了解不多,但“UnauthorizedAccessException”听起来像是一个权限问题。 我想知道是否有人可以为我指出正确的方向,我可能需要做什么才能让我的小应用程序访问使用单词。

I am trying to edit a word document from VB.NET using for the most part this code:

How to automate Word from Visual Basic .NET to create a new document
http://support.microsoft.com/kb/316383

It works fine on my machine but when i publish to the server i get the following error.

Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.

Description: An unhandled exception occurred during the
execution of the current web request.
Please review the stack trace for more
information about the error and where
it originated in the code.

Exception Details: System.UnauthorizedAccessException:
Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.

The actual error happens when i try to just create a word application object

 Dim oWord As New Word.Application

Using Visual Studio 2008 and VB.NET 3.5. I made a reference to the "Microsoft Word 10.0 Object Library" and i see Interop.Word.dll file in the bin directory.

Using MS Office 2003 on development machine and Windows Server 2003

Still fairly new to .NET and don't have much knowledge about window server, but "UnauthorizedAccessException" sounds like a permission issue. I'm wondering if someone could point me in the right direction on what i might need to do to give my little application access to use word.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

陪我终i 2024-08-05 04:29:49

这听起来绝对像是权限问题。 您是否在 Windows 服务中运行代码? 该服务通常作为本地系统运行,可能没有访问 Word 对象模型的权限。 此外,如果 word 已经使用其他用户的凭据运行,那么您的程序可能无法使用不同的凭据通过 COM 访问它。 办公应用程序往往是单实例,这似乎加剧了这个问题。

It definitely sounds like a permissions problem. Are you running your code in a windows service? The service normally runs as Local System, which may not have permission to access the Word object model. Additionally, if word is already running using the credentials of some other user then your program may not be able to access it via COM using different credentials. The office applications tend to be single instance which seems to exacerbate this problem.

陌上青苔 2024-08-05 04:29:49

就我而言,Word 通过服务帐户下的 Windows 服务运行。

问题是 C:\Windows\System32\config\systemprofile 中不存在 Desktop 文件夹(或 C:\Windows\SysWOW64\config\systemprofile) 。

添加它为我解决了这个问题。

In my case, Word is running through a Windows Service under a service account.

The problem was that the Desktop folder didn't exist in C:\Windows\System32\config\systemprofile (or in C:\Windows\SysWOW64\config\systemprofile).

Adding it resolved the issue for me.

沧笙踏歌 2024-08-05 04:29:49

听起来您在 DCOM 中可能存在权限问题。 尝试在 DCOM 配置中编辑 Word 权限。

It sounds like you may have a permission issue in DCOM. Try editing the Word permissions in DCOM config.

似最初 2024-08-05 04:29:49

我遇到了同样的问题,我发现的问题区域是“DCOM 中 Microsoft Word 的安全配置”。在以下链接中,您可以找到分步指南,了解如何在 DCOM 中配置组件,对WORD重复这些步骤,你的问题就解决了。

http://www.biocompsystems.com/_public/DCOMConfigurationStepbyStepForXP.doc

谢谢,
苏希尔·金德尔

I was experiencing the same issue and the problem area I found was "security configuration for Microsoft Word in DCOM". On the following link you can find a step by step guide to know how to config components in DCOM, repeate these steps for WORD, and your problem will be solved.

http://www.biocompsystems.com/_public/DCOMConfigurationStepbyStepForXP.doc

Thanks,
Sushil Jinder

ㄟ。诗瑗 2024-08-05 04:29:49

我在 Windows 2008 R2 上也遇到了同样的问题。 最终使用了这篇文章:
http://social. msdn.microsoft.com/Forums/en-US/netfx64bit/thread/65a355ce-49c1-47f1-8c12-d9cf5f23c53e

然后将web.config中的模拟身份用户更改为其他用户即可解决。

我确信有多种解决方案的组合。

I had the same issue on Windows 2008 R2. Ended up using this post:
http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/65a355ce-49c1-47f1-8c12-d9cf5f23c53e

and then changing the impersonation identity user in web.config to another user to solve it.

I'm sure there is a combination of solutions.

驱逐舰岛风号 2024-08-05 04:29:49

转到开始 -> 运行
输入regedit -32并按回车键。

--注册表编辑器将打开。

转到注册表HKEY_CLASSES_ROOT\Word.Application

选择Word.Application并为以下用户设置完全权限:-

管理员、管理员、本地服务、系统、服务、交互和用户。

Go to Start -> Run
type regedit -32 and press enter key.

-- Registry Editor will get open.

Go To registry HKEY_CLASSES_ROOT\Word.Application

Select Word.Application and set full permission to below users:-

Administrator, Administrators, Local Service, System, Service, Interactive and Users.

亢潮 2024-08-05 04:29:49

我在生成word文档时遇到了同样的问题。 我通过检查任务管理器并结束当前运行的进程 WINWORD.EXE 然后再次执行我的代码解决了这个问题。 问题消失了。

I had the same problem while generating word document. The issue i solved by checking the task manager, and by ending the currently running process WINWORD.EXEs and then executed my code again. The issue gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文