我读一个名单的小岛屿发展中国家从注册表, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.

如何将一个解决显示用户名(例如 DOMAIN\user, BUILT-IN\user)鉴于SID串在C#?

有帮助吗?

解决方案

Win32API功能 LookupAccountSid() 是用来找到这个名字,对应于一个SID。

LookupAccountSid() 具有以下特征:

BOOL LookupAccountSid(LPCTSTR lpSystemName, PSID Sid,LPTSTR Name, LPDWORD cbName,
                       LPTSTR ReferencedDomainName, LPDWORD cbReferencedDomainName,
                       PSID_NAME_USE peUse);

MSDN Ref.

这里的P/援用参考(与样本代码): http://www.pinvoke.net/default.aspx/advapi32.LookupAccountSid

[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError = true)]
static extern bool LookupAccountSid (
  string lpSystemName,
  [MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
  StringBuilder lpName,
  ref uint cchName,
  StringBuilder ReferencedDomainName,
  ref uint cchReferencedDomainName,
  out SID_NAME_USE peUse); 

其他提示

刚刚发现它在 pinvoke.net

替代托管API: 可用在NET 2.0:

using System.Security.Principal;

// convert the user sid to a domain\name
string account = new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top