You see quite a few code samples for retrieving “FullName” (or other properties) from an Active Directory that look like this:

string directoryPath = "WinNT://somedomain/someuser";
string fullName;

DirectoryEntry directoryEntry = new DirectoryEntry(directoryPath);
if (directoryEntry.Properties["FullName"].Value != null)
fullName = directoryEntry.Properties["FullName"].Value.ToString();

One issue with this code is that when “somedomain” actually corresponds to the local
machine name (because your are trying to retrieve the “FullName” of a local account),
it can take an extremely long time to run. This is probably because the underlying
framework is off trying to find a domain controller before falling back to the local
security store.

To work around this, consider code that would look like the following when formulating
the directory path:

string[] identities = windowsIdentity.Name.Split('\\');
string directoryPath;
if (Environment.UserDomainName.ToLower() == Environment.MachineName.ToLower())
// special case needed for "off domain" case.
directoryPath = "WinNT://localhost/" + identities[1];
directoryPath = "WinNT://" + identities[0] + "/" + identities[1];

Using “localhost” will cause the property retrieval to be just about instantaneous,
whereas using the computer name (from a local account Windows identity) results in
up to a twelve second delay.