SecurityIdentifier sid = new SecurityIdentifier("S-1-5-21-3623811015-3361044348-30300820-1013"); string sidString = sid.ToString(); Console.WriteLine(sidString);
NTAccount userAccount = new NTAccount(Environment.UserDomainName, Environment.UserName); SecurityIdentifier userSid = (SecurityIdentifier)userAccount.Translate(typeof(SecurityIdentifier)); string userSidString = userSid.ToString(); Console.WriteLine(userSidString);This example demonstrates how to retrieve the security identifier for the current user. We first create an NTAccount object representing the current user and then call the Translate method to retrieve the corresponding SecurityIdentifier object. Finally, we call ToString to return the string representation of the SID. The System.Security.Principal namespace is part of the .NET Framework Class Library.