SID의 디스플레이 사용자 이름을 해결하는 가장 좋은 방법은?

StackOverflow https://stackoverflow.com/questions/380031

  •  22-08-2019
  •  | 
  •  

문제

레지스트리에서 SIDS 목록을 읽었습니다. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.

디스플레이 사용자 이름을 어떻게 해결합니까 (예 : DOMAIN\user, BUILT-IN\user) C#의 SID String이 주어 졌습니까?

도움이 되었습니까?

해결책

Win32 API 기능 LookupAccountSid() SID에 해당하는 이름을 찾는 데 사용됩니다.

LookupAccountSid() 다음 서명이 있습니다.

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

MSDN 심판.

다음은 P/Invoke 참조 (샘플 코드 포함)입니다. 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