在Windows服务中调用COM接口功能出错 [英] In the windows service to call the COM interface function error

查看:1094
本文介绍了在Windows服务中调用COM接口功能出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的开发工具是 VS2010 ,开发语言是 C#,操作系统是 WINDOWS7 64位.我需要在Windows服务应用程序中调用COM服务(OPC DA Automation Wrapper 2.02)的接口功能,而COM服务和Windows服务位于同一台计算机上.事实证明,调用某些COM接口函数可以成功,但是某些调用有错误(捕获了System.Runtime.InteropServices.COMException).

错误是:
System.Runtime.InteropServices.COMException被捕获
消息=来自HRESULT的异常:0xC0040007
来源= GWOPC.NET
ErrorCode = -1073479673


我创建了一个普通的应用程序(不是Windows服务程序)来调用COM服务,没有问题.所以我认为问题是由于Windows服务的使用引起的,我怀疑是Windows服务的一些权限设置问题.然后,我尝试了以下步骤:
1.我使用管理员帐户登录计算机.
2.在Windows服务属性中->在登录"选项卡上,默认情况下选择本地系统帐户".
3.运行我的Windows服务应用程序以调用COM接口函数,存在错误.
4.在Windows服务属性中->在登录"选项卡上,选择此帐户",然后输入用户名和密码(该用户是管理员).
5.运行我的Windows服务应用程序以调用COM接口函数,该错误仍然存​​在.

相同的代码,一般的应用(例如EXE)调用,不会有任何错误.只有在服务调用中才会出错.

My development tool is VS2010, development language is C#, and operating system is WINDOWS7 64-bit. I need to call interface functions of COM service (OPC DA Automation Wrapper 2.02) in my windows service application, while the COM service and windows service are on the same computer. It turns out that calling some of the COM interface functions successes, but some have errors(System.Runtime.InteropServices.COMException was caught).

errors is:
System.Runtime.InteropServices.COMException was caught
Message=Exception from HRESULT: 0xC0040007
Source=GWOPC.NET
ErrorCode=-1073479673


I created a normal application(not a windows service program) to call the COM service, there was no problem. So I think the problem is due to using of windows service, and I suspect are some permission setting problem of windows service. Then I tried these steps:
1. I log in my computer using an administrator account.
2. In the windows service properties -> Log On tab, select "Local System account" by default.
3. Run my windows service application to call COM interface functions, error exists.
4. In the windows service properties -> Log On tab, select "This Account" and enter a user name and password (the user is an administrator).
5. Run my windows service application to call COM interface functions, the error still exists.

Same code, the general application(e.g. EXE) call, there will be no errors. Only in the service call, will have errors.

推荐答案

听起来您正在尝试从Windows服务中调用某些COM功能.默认情况下,该服务将在高度锁定的帐户中运行-您需要做的是创建一个帐户(使用强密码),以使该服务在其中运行.为其赋予适当的特权(例如访问注册表),并它应该能够工作.
It sounds like you are attempting to call some COM functionality from within a windows service. By default, the service will run in a highly locked down account - what you need to do is create an account (with a strong password), for the service to run in. Give it appropriate privileges (such as access the registry), and it should be able to work.


这篇关于在Windows服务中调用COM接口功能出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆