Class Impersonator
Impersonation of a user. Allows to execute code under another user context. Please note that the account that instantiates the Impersonator class needs to have the 'Act as part of operating system' privilege set.
Inheritance
Namespace: Cireson.Core.Common.Helpers
Assembly: Cireson.Core.Common.dll
Syntax
public class Impersonator : IDisposable
Remarks
This class is based on the information in the Microsoft knowledge base article http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306158
Encapsulate an instance into a using-directive like e.g.:
... using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) ) { ... [code that executes under the new context] ... } ... See also http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a- User for original unaltered code base for this implementation.
Constructors
View SourceImpersonator(String, String, String)
Constructor. Starts the impersonation with the given credentials. Please note that the account that instantiates the Impersonator class needs to have the 'Act as part of operating system' privilege set.
Declaration
public Impersonator(string userName, string domainName, string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The name of the user to act as. |
System.String | domainName | The domain name of the user to act as. |
System.String | password | The password of the user to act as. |
Remarks
Admin, 8/24/2017.
Methods
View SourceDispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Remarks
Admin, 8/24/2017.