Calling A COM Component From .NET Windows Service
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 t开发者_如何学JAVAest 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?
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/
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.
精彩评论