通过 Server 2008 上的 Windows 服务实现 Office 自动化

发布于 2024-07-25 00:00:21 字数 560 浏览 4 评论 0原文

我们有一个在 2003 Server 上运行的 Windows 服务。 它使用 Word Interop 打开源 Word 文档,然后对其执行一些操作。 Excel 和 PowerPoint 文件也同样如此。

最近,我们尝试将此服务移至 Windows 2008 Server 计算机上,但遇到了实际问题。

Microsoft.Office.Interop.Excel.Workbooks.Open 处的 COMException Microsoft.Office.Interop.Word.Documents.Open 处的 COMException

当 Windows 服务在 2008 Server 上运行时,我收到上述异常。 查看任务管理器,应用程序加载正常,但不久后再次关闭。

我读过有关 Vista 和 Server 2008 不再具有 Session0 的内容,并尝试相应地更改 Office DCOM 安全属性,包括将运行它们的用户的身份更改为“集成”,但无济于事。

有谁知道这是否可能? 这是我们系统的一个基本方面,因此我们需要能够做到这一点。

谢谢

We have a Windows Service which runs on 2003 Server. It opens a source Word document using the Word Interop and then does some stuff with it. It also does likewise with Excel and PowerPoint files.

Recently we've tried moving this service onto a Windows 2008 Server machine and are having real problems with it.

COMException at Microsoft.Office.Interop.Excel.Workbooks.Open
COMException at Microsoft.Office.Interop.Word.Documents.Open

I get the above exceptions when the windows service is running on 2008 Server. Looking at the Task Manager, the application does load ok, but then closes again shortly after.

I've read things about Vista and Server 2008 not having a Session0 anymore, and have tried changing the Office DCOM security properties accordingly, including changing the identity of the user running them to Integrated but to no avail.

Does anyone know if this is possible at all? This is a fundamental aspect of our system and so we need to be able to do this.

Thanks

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

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

发布评论

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

评论(4

说不完的你爱 2024-08-01 00:00:21

我在 Windows Server 2008 下通过 Windows 服务自动化 Office 时遇到问题,即使在 Windows Server 2003 下工作正常。该问题也出现在 Open 调用中,因此可能是同一问题。

我尝试遵循 H Okawa 在 这个 MSDN 线程,它似乎有效。 这很奇怪,但值得称赞的是小川先生发现了它。

“Okawa Hack”摘要:为系统配置文件创建一个桌面文件夹,如下所示:

 C:\Windows\System32\config\systemprofile\Desktop

并且,如果在 64 位计算机上运行,​​则创建另一个一个,如下所示:

 C:\Windows\SysWOW64\config\systemprofile\Desktop

此外,文件夹需要“驱动”Office 的任何用户的写入权限。


[编辑:更正链接 URL]

[编辑 2:澄清在 64 位 Windows 上,您需要这两个文件夹,而不仅仅是 WOW64 文件夹]

I've had problems automating Office from a Windows Service under Windows Server 2008, even though that works fine under Windows Server 2003. The problem also occurs at the Open call, so it may be the same problem.

I tried following the advice given by H Ogawa in this MSDN thread, and it seemed to work. It's bizarre, but kudos to Mr. Ogawa for discovering it.

Summary of the 'Ogawa Hack': create a desktop folder for the system profile, as:

 C:\Windows\System32\config\systemprofile\Desktop

and, if running on a 64-bit machine, create another one, as:

 C:\Windows\SysWOW64\config\systemprofile\Desktop

Also, the folder(s) need write permission for whatever user is "driving" Office.


[Edit: corrected link URL]

[Edit 2: clarified that on 64-bit Windows, you need both folders, not just the WOW64 one]

再浓的妆也掩不了殇 2024-08-01 00:00:21

如果您使用的是 Apache,您可能还需要按照以下步骤使 MS Word 正常工作(以及其他答案中概述的所有内容):

下面的屏幕截图显示了您需要打开的两个对话框:
在此处输入图像描述

对于 Apache:

服务 -> Apache -> 右键单击​​(属性)-> 登录选项卡

MS Word:

启动 dcomcnfg.exe->控制台根目录->组件服务->计算机->我的电脑->DCOM Config->查找 Microsoft 应用程序->右键单击(属性)->身份选项卡

**如果找不到 MS Word,请确保根据您安装的 Office 版本启动正确的 DCOM 配置(64 位与 32 位)。

这里有两个选项,您可以将 Apache 设置为使用本地系统帐户并选中复选框以允许桌面交互。 如果您这样做,则需要将 MS Word 的身份设置为交互式用户

否则,您需要将两者设置为同一用户(最好是登录的用户),如图所示。

If you are using Apache, you might also need to follow these steps to get MS Word working properly (along with everything outlined in other answers):

Below is a screenshot showing the two dialogs you'll need to bring up:
enter image description here

For Apache:

Services->Apache->Right Click (Properties)->Log On Tab

MS Word:

Launch dcomcnfg.exe->Console Root->Component Services->Computers->My Computer->DCOM Config->Find Microsoft Application->Right Click(Properties)->Identity Tab

**if you can't find the MS Word, make sure you are launching the correct DCOM Config (64 bit vs 32 bit) depending on what version of Office you have installed.

There are two options here, you can set Apache to use Local System Account and check the checkbox to ALLOW desktop interaction. If you do this then you need to set the Identity for MS Word to Interactive User.

Otherwise, you need to set both to the same user (Ideally the user that is logged in) like shown in the picture.

青瓷清茶倾城歌 2024-08-01 00:00:21

出色地,
您需要运行“MMC -32”(命令提示符)来启动 32 位 MMC,然后添加组件服务(文件 > 添加/删除管理单元菜单),

然后按照以下说明之一进行操作:

http://theether.net/download/Microsoft/kb/288366.html

Well,
you will need to run "MMC -32" (command prompt) to launch 32-bit MMC and then add Component Services (File > Add / Remove Snap-ins' menu)

then follow one of these instruction:

http://theether.net/download/Microsoft/kb/288366.html

苏大泽ㄣ 2024-08-01 00:00:21

在启用 UAC 的 Vista 上也会发生这种情况。 您可能需要尝试将 DCOM 身份设置为管理员帐户并再次测试。

我最近也开始在 XP 机器上尝试通过互操作服务在 Excel 中打开工作簿时遇到此问题,但尚未找到解决方法。 我本人希望社区能够提出任何其他见解......

This also happens on Vista with UAC enabled. You might want to try setting the DCOM identity to be an administrator account and test it again.

I also recently started having this problem on an XP box trying to open workbooks in Excel through interop services, but have not yet found a workaround. I myself would like any other insights the community might be able to throw out there...

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