views:

643

answers:

4

How can I login to AD without logout from current user and get new logged user's rights. (OS: Windows XP)

Note:

Not to Modify AD or something like this.Only wanna to login with another user from C# and getting new login's permissions/rights. (I wanna use this rights not only in current thread but also whole explorer. Like deleting files, creating directories, changing Network options.)

Is this possible?

A: 

Maybe this article might be helpful. It is a tutorial on WindowsImpersonationContext.

Andrew Hare
A: 

Look at using LogonUser to do impersonation. It will require that you have their password.

tvanfosson
A: 

You would call the LogonUser API function through the P/Invoke layer and then pass the handle returned to the Impersonate method on the WindowsIdentity class. Details on how to do so are in the documentation for the Impersonate method on the WindowsIdentity class, located here:

http://msdn.microsoft.com/en-us/library/chf6fbt4.aspx

casperOne
+1  A: 

You can use impersonation to change thread identity to a different user, given a valid username and password. There is no way to change the user identity for the whole shell other than logging in as a different user manually, but anything executed on the thread you impersonate on will receive the new rights.

The .NET 1.1 way, using P/Invoke:

The .NET 2+ way, using Thread.CurrentPrincipal:

Chris Hynes
so there is no way to change the user identity for the whole shell other than logging in as a different user manually ?? i dont wanna run a code . i wanna login and grab the whole shell with this new identity.
Ozlem Balli
No, you'd have to log in as a user manually. However, I would think if you run a process from an impersonated thread it would keep the identity of the thread. Take a look at the System.Diagnostics.Process class - maybe you can create a process under the same impersonated identity to do what you want
Chris Hynes