在C#中将SID转换为用户名

编程入门 行业动态 更新时间:2024-10-27 08:24:00
本文介绍了在C#中将SID转换为用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

In , 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转换为用户名

本文发布于:2023-11-09 15:18:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572710.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   用户名   SID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!