Export (0) Print
Expand All

WindowsImpersonationContext.Undo Method

Reverts the user context to the Windows user represented by this object.

[Visual Basic]
Public Sub Undo()
[C#]
public void Undo();
[C++]
public: void Undo();
[JScript]
public function Undo();

Exceptions

Exception Type Condition
SecurityException An attempt is made to use this method for any purpose other than to revert identity to self.

Remarks

Notes to Implementers:  Because Microsoft Windows 98 and Windows Millennium Edition platforms do not have users or user tokens, impersonation cannot take place on those platforms.

Example

[Visual Basic, C#, C++] The following example shows how to impersonate a Windows identity using a specified user token.

[Visual Basic] 
Dim ImpersonationCtx As WindowsImpersonationContext = _
   WindowsIdentity.Impersonate(userToken)
'Do something under the context of the impersonated user. 
ImpersonationCtx.Undo()


[C#] 
WindowsImpersonationContext ImpersonationCtx = WindowsIdentity.Impersonate(userToken); 
//Do something under the context of the impersonated user.
 ImpersonationCtx.Undo();


[C++] 
WindowsImpersonationContext* ImpersonationCtx = WindowsIdentity::Impersonate(userToken); 
//Do something under the context of the impersonated user.
 ImpersonationCtx->Undo();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

WindowsImpersonationContext Class | WindowsImpersonationContext Members | System.Security.Principal Namespace

Show:
© 2014 Microsoft