Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SID to Username in C#

Tags:

c#

.net

sid

In .net, I can create a NTAccount using domain and username, and get it's SID.

But I cannot convert the SID back to NTAccount using translate function.

new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();

And this two way conversion code has no problem running on Domain Controller.

Maybe some configuration wrong?

like image 249
user970444 Avatar asked Mar 11 '26 10:03

user970444


1 Answers

SecurityIdentifier.Translate() method works only on domain accounts so perhaps your computer not attached to domain. To resolve local SIDs into account name you can use Win32 API function LookupAccountSid() look here for example.

like image 120
Alexander Avatar answered Mar 14 '26 00:03

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!