Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Win32, call <a href="http://msdn.microsoft.com/en-us/library/aa446671.aspx" rel="noreferrer">GetTokenInformation</a>, passing a token handle and the <code>TokenUser</code> constant. It will fill in a <a href="http://msdn.microsoft.com/en-us/library/aa379634.aspx" rel="noreferrer">TOKEN_USER</a> structure for you. One of the elements in there is the user's SID. It's a BLOB (binary), but you can turn it into a string by using <a href="http://msdn.microsoft.com/en-us/library/aa376399.aspx" rel="noreferrer">ConvertSidToStringSid</a>.</p> <p>To get hold of the current token handle, use <a href="http://msdn.microsoft.com/en-us/library/aa379296(VS.85).aspx" rel="noreferrer">OpenThreadToken</a> or <a href="http://msdn.microsoft.com/en-us/library/aa379295(VS.85).aspx" rel="noreferrer">OpenProcessToken</a>.</p> <p>If you prefer ATL, it has the <a href="http://msdn.microsoft.com/en-us/library/f42z4h7d(VS.80).aspx" rel="noreferrer">CAccessToken</a> class, which has all sorts of interesting things in it.</p> <p>.NET has the <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentprincipal.aspx" rel="noreferrer">Thread.CurrentPrinciple</a> property, which returns an IPrincipal reference. You can get the SID:</p> <pre><code>IPrincipal principal = Thread.CurrentPrincipal; WindowsIdentity identity = principal.Identity as WindowsIdentity; if (identity != null) Console.WriteLine(identity.User); </code></pre> <p>Also in .NET, you can use WindowsIdentity.GetCurrent(), which returns the current user ID:</p> <pre><code>WindowsIdentity identity = WindowsIdentity.GetCurrent(); if (identity != null) Console.WriteLine(identity.User); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload