简体   繁体   中英

.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?

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.

To repeat my comment as an answer:

Instead of drive-mappings, can you directly access the UNC file paths instead?

Adding another point regarding impersonation :

You could impersonate the code lines you have to run under the other user through (eg) my Impersonator class , I wrote some years back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM