Search code examples
.netcomserviceinteropaccount

.NET Com Interop Account


I am writing a .NET windows service in C#. This is being run under the local system account. However, this service needs to call an old COM component. This old COM component contains lots of file access using mapped drive letters to network drives (it's not very nice but I can't rewrite it). I assume that this COM component is also being loaded under the local system account and therefore these drive mappings will fail because they do not exist.

What are the ways round this? Can I load the COM component under a user account which does have these mappings? If so how? Or is there a better way

Will running the whole windows service under a user account get round the problem?


Solution

  • You could host the component as a COM+ application which would allow you to specify what account the user runs under. You would then have to do the appropriate work to access the COM component correctly in .NET, but it should work.

    Another option is to have a service that can run under the account for you and then make calls through WCF to make the calls in the server.

    The principal for both is the same though, you basically make the call in another app domain and shuttle the request/response between the other app domain and the one your application runs in.