I am looking for an easy way to get the SID for the current Windows user account. I know I can do it through WMI, but I don\'t want to go that route.
Apologies to ev
ATL::CAccessToken accessToken;
ATL::CSid currentUserSid;
if (accessToken.GetProcessToken(TOKEN_READ | TOKEN_QUERY) &&
accessToken.GetUser(¤tUserSid))
return currentUserSid.Sid();
I found another way to get SID:
System.Security.Principal.WindowsIdentity id = System.Security.Principal.WindowsIdentity.GetCurrent();
string sid = id.User.AccountDomainSid.ToString();
in cmd.exe
whoami /user
if you need it programatically, please ask more specified
This should give you what you need:
using System.Security.Principal;
...
var sid = WindowsIdentity.GetCurrent().User;
The User property of WindowsIdentity returns the SID, per MSDN Docs
This one is the shortest of them all I believe.
UserPrincipal.Current.Sid;
Available with .net >= 3.5