<Type Name="WindowsImpersonationContext" FullName="System.Security.Principal.WindowsImpersonationContext">
  <TypeSignature Maintainer="auto" Language="C#" Value="public class WindowsImpersonationContext : IDisposable" />
  <AssemblyInfo>
    <AssemblyName>mscorlib</AssemblyName>
    <AssemblyPublicKey>[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00]</AssemblyPublicKey>
    <AssemblyVersion>1.0.5000.0</AssemblyVersion>
    <AssemblyVersion>2.0.0.0</AssemblyVersion>
    <AssemblyVersion>4.0.0.0</AssemblyVersion>
  </AssemblyInfo>
  <ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the &lt;link location="node:gtk-sharp/programming/threads"&gt;Gtk# Thread Programming&lt;/link&gt; for details.</ThreadSafetyStatement>
  <Base>
    <BaseTypeName>System.Object</BaseTypeName>
  </Base>
  <Interfaces>
    <Interface>
      <InterfaceName>System.IDisposable</InterfaceName>
    </Interface>
  </Interfaces>
  <Docs>
    <summary>This class holds the impersonation context and the possibility to revert to the original identity.</summary>
    <remarks>The WindowsImpersonationContext class can also be used on POSIX compliant operating system.

<example><code lang="C#">
using System;
using System.IO;
using System.Security.Principal;

class WinId {

     static string file = "root.txt";

     static void Show (string msg) 
     {
          Console.WriteLine (msg);
          WindowsIdentity wi = WindowsIdentity.GetCurrent ();
          Console.WriteLine ("\tUserName:\t{0}", wi.Name);
          Console.WriteLine ("\tToken:\t\t{0}", wi.Token);
          Console.WriteLine ();
     }

     static void Show (Exception e) 
     {
          Console.WriteLine ("Oops something has gone bad...");
          Console.WriteLine (e.ToString ());
     }

     static void DisplayFile (string filename) 
     {
          Console.WriteLine ("Trying to read file {0}", filename);
          try {
               using (StreamReader sr = File.OpenText (filename)) {
                    Console.WriteLine (sr.ReadToEnd ());
                    sr.Close ();
               }
          }
          catch (Exception e) {
               Show (e);
          }
     }

     static void DeleteFile (string filename) 
     {
          Console.WriteLine ("Trying to delete file {0}", filename);
          try {
               File.Delete (filename);
          }
          catch (Exception e) {
               Show (e);
          }
     }

     [STAThread]
     static void Main (string[] args)
     {
          bool fileCreated = false;

          Show ("Current User");
          bool posix = ((int)Environment.OSVersion.Platform == 128);
          bool root = (WindowsIdentity.GetCurrent ().Token == IntPtr.Zero);
          if (root &amp;&amp; posix) {
               Console.WriteLine ("Cool you're root!");
               
               Console.WriteLine ("Let's create a file {0}.", file);
               using (StreamWriter sw = new StreamWriter (file)) {
                    sw.WriteLine ("FOR ROOT EYES ONLY");
                    sw.Close ();
               }
               fileCreated = true;
               DisplayFile (file);

               Console.WriteLine ("Now, who do you want to be today ? ");
               string username = Console.ReadLine ();
               WindowsIdentity nonroot = new WindowsIdentity (username);

               Console.WriteLine ("Trying to impersonate {0} (token: {1})",
                    nonroot.Name, nonroot.Token);
               WindowsImpersonationContext wic = null;
               try {
                    wic = nonroot.Impersonate ();
                    Show ("Impersonated User");
                    DisplayFile (file);
                    DeleteFile (file);
               }
               catch (Exception e) {
                    Show (e);
               }
               finally {
                    if (wic != null) {
                         wic.Undo ();
                         wic = null;
                    }
               }

               Show ("Back to original User");
               if (File.Exists (file)) {
                    DisplayFile (file);
                    DeleteFile (file);
               }
               else if (fileCreated) {
                    Console.WriteLine ("Hey dude, where's my file ?");
               }
          }
          else {
               Console.WriteLine ("Sorry, not much fun to have with non-root users.");
          }
     }
}  </code></example></remarks>
  </Docs>
  <Members>
    <Member MemberName="Dispose">
      <MemberSignature Language="C#" Value="public void Dispose ();" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters />
      <Docs>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
        <since version=".NET 2.0" />
      </Docs>
      <AssemblyInfo>
        <AssemblyVersion>2.0.0.0</AssemblyVersion>
        <AssemblyVersion>4.0.0.0</AssemblyVersion>
      </AssemblyInfo>
      <Attributes>
        <Attribute>
          <AttributeName>System.Runtime.InteropServices.ComVisible(false)</AttributeName>
        </Attribute>
      </Attributes>
    </Member>
    <Member MemberName="Dispose">
      <MemberSignature Language="C#" Value="protected virtual void Dispose (bool disposing);" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="disposing" Type="System.Boolean" />
      </Parameters>
      <Docs>
        <param name="disposing">To be added.</param>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
        <since version=".NET 2.0" />
      </Docs>
      <AssemblyInfo>
        <AssemblyVersion>2.0.0.0</AssemblyVersion>
        <AssemblyVersion>4.0.0.0</AssemblyVersion>
      </AssemblyInfo>
      <Attributes>
        <Attribute>
          <AttributeName>System.Runtime.InteropServices.ComVisible(false)</AttributeName>
        </Attribute>
      </Attributes>
    </Member>
    <Member MemberName="Finalize">
      <MemberSignature Language="C#" Value="~WindowsImpersonationContext ();" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters />
      <Docs>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
      <AssemblyInfo>
        <AssemblyVersion>1.0.5000.0</AssemblyVersion>
      </AssemblyInfo>
    </Member>
    <Member MemberName="Undo">
      <MemberSignature Language="C#" Value="public void Undo ();" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters />
      <Docs>
        <summary>Revert to the previous identity.</summary>
        <remarks>To be added</remarks>
      </Docs>
      <AssemblyInfo>
        <AssemblyVersion>1.0.5000.0</AssemblyVersion>
        <AssemblyVersion>2.0.0.0</AssemblyVersion>
        <AssemblyVersion>4.0.0.0</AssemblyVersion>
      </AssemblyInfo>
    </Member>
  </Members>
  <Attributes>
    <Attribute>
      <AttributeName>System.Runtime.InteropServices.ComVisible(true)</AttributeName>
    </Attribute>
  </Attributes>
</Type>
