Logout after logging in to C #

I am using the logonuser advapi32.dll method to access data through our network.
I know that he changes the user of the stream to the information that I give him, but I was wondering if there is a way to change it.
I want to access the data and then return to the local user credentials.

+5
source share
2 answers

Some time ago I created a small impersonator class .

Basically, you end your code to execute as another user, just inside a block using:

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   ...

   <code that executes under the new context>

   ...
}

Worked well for my projects.

+7

RevertToSelf.

, -, , , . , , - , , . , , , .

+1

All Articles