Question

J'ai lu une liste de SIDs du registre, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.

Comment peut-on résoudre le nom d'utilisateur d'affichage (par exemple DOMAIN\user, BUILT-IN\user) compte tenu de la chaîne SID en C #?

Était-ce utile?

La solution

La fonction API Win32 LookupAccountSid() est utilisé pour trouver le nom qui correspond à un SID.

LookupAccountSid() a la signature suivante:

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

Ref .

Voici la référence P / Invoke (avec exemple de code): 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); 

Autres conseils

Je viens de trouver sur le pinvoke.net .

API Managed Alternative: Disponible en .Net 2.0:

using System.Security.Principal;

// convert the user sid to a domain\name
string account = new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top