从 .NET Windows 服务调用 COM 组件

发布于 2024-11-16 01:41:12 字数 229 浏览 1 评论 0原文

我有一个用 .NET C# 编写的 Windows 服务,它调用 COM 组件。我还有一个 .NET Windows 窗体测试应用程序,用于测试 COM 组件。从测试应用程序来看它运行良好。但是,当我在 Windows 服务中使用相同的代码时,什么也没有发生。 COM 组件将所有内容记录到文件中,并且未生成日志文件这一事实暗示 COM 组件甚至没有被调用。

为什么这在我的测试应用程序中有效,但在 Windows 服务中无效?

I have a Windows Service written in .NET C# which calls a COM component. I also have a .NET Windows Forms test app which I was using to test the COM component. It works fine from the test app. However, when I use the same code in the Windows Service nothing happens. The COM components logs everything to file and the fact the log file doesn't get produced hints that the COM component isn't even being called.

Why does this work from my test app but not within the windows service?

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

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

发布评论

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

评论(2

久而酒知 2024-11-23 01:41:12

服务通常与桌面隔离运行,因此当从服务调用时,对 COM 组件的调用与 UI 隔离。您可以允许服务“与桌面交互”,请参阅 >使用交互式服务

Microsoft(<讽刺>以他们无限的智慧)决定从 Windows Vista 中删除此功能并推荐 将应用程序分成多个部分并使用其他机制来完成 UI 和服务之间的通信。显然,有些人(包括我自己)不同意,但是,事情就是这样......

http://msdn.microsoft.com/en-us/library/ms683502.aspx

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e50d8819-d628-48e2-aa2c-6ac6de8380d9/

Service typically run isolated from the desktop, and therefore your call to the COM component is insulated from the UI when called from the service. You may allow a service to "interactWithDesktop" see the section on Using an Interactive Service.

Microsoft (<sarcasm>in their infinite wisdom</sarcasm>) Decided that this capability would be removed from Window vista and recommend separating your application into multiple parts and using other mechanisms to accomplish communication between your UI and your service. Obviously, some (including myself) don't agree, but, it is what it is...

http://msdn.microsoft.com/en-us/library/ms683502.aspx

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e50d8819-d628-48e2-aa2c-6ac6de8380d9/

扮仙女 2024-11-23 01:41:12

您是否在 LocalSystem 帐户(Windows 服务的默认帐户)中运行服务?您的 COM 组件可能需要访问可以正常运行它的帐户中的可用资源...

尝试编辑您的服务并在 登录选项卡

Are you running your service in the LocalSystem account (the default for Windows Services)? Your COM component may need to access resources available in an account that can run it normally...

Try editing your service and specifying your account on the Log On tab.

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