/// <summary>Impersonate using a Generic entry in Credential Manager</summary> /// <remarks>CredentialManager can only return passwords for Generic credentials as per CredentialManager's unit tests</remarks> public static bool Impersonate(string target) { var credential = CredentialManager.GetCredentials(target); if (credential == null) { throw new SecurityException(Utilities.Message(Resources.TargetNotFound, target, CurrentUser)); } try { Impersonator.Impersonate(credential.UserName, credential.Domain, credential.SecurePassword); } catch (Win32Exception exception) { throw new SecurityException(Utilities.Message(Resources.CouldNotImpersonate, credential.UserName, credential.Domain), exception); } return(true); }
/// <summary>Stop impersonating a user</summary> public static bool StopImpersonating() { // Allow a SecurityException to kick in; it will be caught by FitSharp. Impersonator.UndoImpersonation(); return(true); }