mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.5000.0 2.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.Object System.IDisposable This class holds the impersonation context and the possibility to revert to the original identity. The WindowsImpersonationContext class can also be used on POSIX compliant operating system. `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 && 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."); } } }`
- Method
  System.Void To be added. To be added. 2.0.0.0 System.Runtime.InteropServices.ComVisible(false)
- Method
  System.Void `` To be added. To be added. To be added. 2.0.0.0 System.Runtime.InteropServices.ComVisible(false)
- Method
  System.Void To be added. To be added. 1.0.5000.0
- Method
  System.Void Revert to the previous identity. To be added 1.0.5000.0 2.0.0.0
System.Runtime.InteropServices.ComVisible(true)