レジストリから SID のリストを読み取りましたHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
。
C# で SID 文字列が指定された場合、表示ユーザー名 (例: )DOMAIN\user
をどのように解決しますか?BUILT-IN\user
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();
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);