C# Class LazyCopy.Utilities.Impersonator

Contains helper methods for user impersonation.
Mostrar archivo Open project: aleksk/LazyCopy Class Usage Examples

Public Methods

Method Description
Impersonate ( string domainUser ) : System.Security.Principal.WindowsImpersonationContext

Impersonates the specified user within the Explorer process context.
Explorer process is vital for the system and should always be there, if the user is logged in.

Impersonate ( string domainUser, Predicate processFilter ) : System.Security.Principal.WindowsImpersonationContext

Impersonates the specified user.

This method looks for the existing domainUser process running in the system, obtains and duplicates its token, and uses it to impersonate the caller. So it won't work, if the user is logged out or has no processes running.

Private Methods

Method Description
DuplicateProcessHandle ( Process process ) : IntPtr

Duplicates handle for the process given.

Method Details

Impersonate() public static method

Impersonates the specified user within the Explorer process context.
Explorer process is vital for the system and should always be there, if the user is logged in.
is or empty. is not in the DOMAIN\username format. /// No processes are running for the . /// -or- /// Process handle cannot be duplicated. ///
public static Impersonate ( string domainUser ) : System.Security.Principal.WindowsImpersonationContext
domainUser string The domain user.
return System.Security.Principal.WindowsImpersonationContext

Impersonate() public static method

Impersonates the specified user.
This method looks for the existing domainUser process running in the system, obtains and duplicates its token, and uses it to impersonate the caller. So it won't work, if the user is logged out or has no processes running.
is or empty. is not in the DOMAIN\username format. /// No processes are running for the . /// -or- /// Process handle cannot be duplicated. ///
public static Impersonate ( string domainUser, Predicate processFilter ) : System.Security.Principal.WindowsImpersonationContext
domainUser string The domain user.
processFilter Predicate Predicate to find the process suitable for impersonation. If it's , the first 's process will be used.
return System.Security.Principal.WindowsImpersonationContext