使用 Excel 组件可以在应用程序中运行,但不能在 Windows 服务中运行

发布于 2024-12-03 02:12:20 字数 478 浏览 0 评论 0原文

我有一个 .NET Windows 服务,它自行托管 WCF 服务。然后,此 WCF 服务继续调用 Visual Studio 6 上用 ATL 编写的旧 COM 组件。然后,此 COM 组件创建 Excel.Application COM 组件。它调用此 Excel COM 组件上的各种方法,然后调用其上的 SaveAs 来完成文档的保存。此 SaveAs 方法调用失败。 Windows 服务作为本地系统运行,所以我认为这一定是一些权限问题。因此,我更改了 Windows 服务,以便它在我的用户帐户下运行(只需进入 services.msc,停止服务、属性、更改登录并重新启动服务)。然而,同样的问题仍然存在。

我创建了一个快速的 .NET Win Forms 测试应用程序,然后从那里运行 COM 组件。这很好用。该应用程序在我的用户帐户下运行,因此我认为在我的帐户下运行 Windows 服务会产生相同的效果。

Windows 服务有什么问题(即使它在我的用户帐户下运行)?我该如何解决这个问题?

I have a .NET Windows service which self hosts a WCF service. This WCF service then goes on to call an old COM component written in ATL on Visual Studio 6. This COM component then creates a Excel.Application COM component. It calls various methods on this Excel COM component and then calls SaveAs on it to finish saving the document. This SaveAs method call fails. The Windows service is running as Local System so I thought it must be some permission problem. So I changed the windows service so that it ran under my user account (just go into services.msc, stop the service, properties, change log on, and restart the service). However, the same problem persists.

I create a quick .NET Win Forms test app and then run the COM component from there. This works fine. The app is running under my user account so I would have thought running the windows service under my account would have the same effect.

What is the problem with the windows service (even when it is running under my user account)? And how do I solve this?

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

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

发布评论

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

评论(1

离去的眼神 2024-12-10 02:12:20

由于 Vista Windows 服务不允许执行“桌面操作”(安全等)...此外,办公自动化是 在这种情况下 MS 不支持...

您可以找到某种方法来规避这一切,但我强烈建议采取另一条路线 - 对于 Office 文件,有来自 MS 的免费 SDK,您可以使用名为 OpenXML SDK 2.0 - 您可以下载此处

如果功能不够,还有其他免费和商业 SDK - 推荐一些可以帮助您更多地了解您的需求。

Since Vista Windows Service are not allowed to do "Desktop things" (security etc.)... additionally Office automation is NOT supported by MS in this scenario...

You could find some way to circumvent all this BUT I would strongly recommend to take another route - for Office files there is a free SDK from MS you can use called OpenXML SDK 2.0 - you can download it here.

IF the features are not enough there are other free and commercial SDKs out there - to recommend something it would help to know more about your requirements.

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