在C#中将SID转换为用户名 [英] Convert SID to Username in C#

查看:253
本文介绍了在C#中将SID转换为用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.net中,我可以使用域和用户名创建 NTAccount 并获取其SID。

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

但是我无法使用转换功能将SID转换回NTAccount。

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.

也许某些配置错误?

推荐答案

SecurityIdentifier.Translate()方法仅适用于域帐户,因此也许您的计算机未连接到域。要将本地SID解析为帐户名称,可以使用Win32 API函数LookupAccountSid()在此处例如。

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.

这篇关于在C#中将SID转换为用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆