11

レジストリから SID のリストを読み取りましたHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

C# で SID 文字列が指定された場合、表示ユーザー名 (例: )DOMAIN\userをどのように解決しますか?BUILT-IN\user

4

2 に答える 2

29

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();
于 2008-12-19T05:59:02.240 に答える
10

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); 
于 2008-12-19T03:46:04.597 に答える