Jeffrey Kinzer
Jeffrey Kinzer

Reputation: 149

Using ManagementObject or GetProcesses getting and impersonating a context

I want to create a windows service, and be able to impersonate a user that is logged into the box by grabbing the context, maybe through the getprocesses function or the ManagementObject code.

I don't have a password, but the user will be logged into the box where the service is running. This context will then be used for impersonation.

Upvotes: 0

Views: 418

Answers (1)

John Atwood
John Atwood

Reputation: 1535

I'm not sure that what you want to do as described is possible. Without a password, you cannot impersonate another user, unless their is some sort of coordination between your service, and the user you want to impersonate.

This thread has good information about how to impersonate a user: How do you do Impersonation in .NET?

In order to impersonate the user, you need the Win32 user token. You usually get this via the Win32 LogonUser, which requires a password.

You can work around this however, by having the user that you want to impersonate to initiate a request with your service. You can do this via a start up task, manual user action, or other methods. If you are able to do this, you might want to consider us WCF to create your service. WCF allows you to configure your service to impersonate the user that is making the service call.

Upvotes: 1

Related Questions