2 using Microsoft.Win32.SafeHandles;
14 private SafeAccessTokenHandle m_safeTokenHandle = SafeAccessTokenHandle.InvalidHandle;
18 private FrameSecurityDescriptor m_fsd;
28 if (safeTokenHandle.IsInvalid)
34 if (!Win32Native.DuplicateHandle(Win32Native.GetCurrentProcess(), safeTokenHandle, Win32Native.GetCurrentProcess(), ref m_safeTokenHandle, 0u, bInheritHandle:
true, 2u))
45 [SecuritySafeCritical]
49 if (m_safeTokenHandle.IsInvalid)
51 num = Win32.RevertToSelf();
59 num = Win32.RevertToSelf();
64 num = Win32.ImpersonateLoggedOnUser(m_safeTokenHandle);
73 m_fsd.SetTokenHandles(
null,
null);
78 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
79 [HandleProcessCorruptedStateExceptions]
80 internal bool UndoNoThrow()
86 if (m_safeTokenHandle.IsInvalid)
88 num = Win32.RevertToSelf();
96 num = Win32.RevertToSelf();
99 num = Win32.ImpersonateLoggedOnUser(m_safeTokenHandle);
103 Environment.FailFast(Win32Native.GetMessage(num));
111 m_fsd.SetTokenHandles(
null,
null);
123 [SecuritySafeCritical]
125 protected virtual void Dispose(
bool disposing)
127 if (disposing && m_safeTokenHandle !=
null && !m_safeTokenHandle.IsClosed)
130 m_safeTokenHandle.Dispose();
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
virtual void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.Security.Principal.WindowsImpersonationContext ...
void Undo()
Reverts the user context to the Windows user represented by this object.
Cer
Specifies a method's behavior when called within a constrained execution region.
Represents a Windows user.
Provides information about, and means to manipulate, the current environment and platform....
void Dispose()
Releases all resources used by the T:System.Security.Principal.WindowsImpersonationContext.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
The exception that is thrown when one of the arguments provided to a method is not valid.
Consistency
Specifies a reliability contract.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
The exception that is thrown when a security error is detected.
Represents the Windows user prior to an impersonation operation.
static void FailFast(string message)
Immediately terminates a process after writing a message to the Windows Application event log,...