1
votes

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?

2
Instead of drive-mappings, can you directly access the UNC file paths instead?Uwe Keim
Can't you run the service under a system account?Oded
I'm assuming he can't, but even that wouldn't help. Try stackoverflow.com/questions/125341/impersonation-in-net , it might be what you're looking for.Vladislav Zorov
@Uwe Keim's has the answer. That system user is has somewhat strange local-only privileges. Another approach is to run as a user you created and provide with the necessary privs.kenny

2 Answers

0
votes

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.

0
votes

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 (e.g.) my Impersonator class, I wrote some years back.