

OutputString += key + " = " + propValue + "." ĭepending on the data in your active directory, you will get a varied response in the output.Converting a local user to an Active Directory userĪlthough local user accounts can co-exist with Active Directory user accounts, in some cases, you may want to convert some or all of your local accounts to Active Directory user accounts. Each property contains a collection of its ownįoreach (Object propValue in result.Properties) Get a directory entry from ldap and the domain name: DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://)", username) Get the current domain: .GetCurrentDomain() There's a class called DirectorySearcher that maybe I'm supposed to use, but it wants a domain name, and I don't know how to get that either - all I have is the path to the directory I'm scanning.

This seems like it will work, in that the access to "dirEntry.Name" hangs for a few seconds, as if it is going off and querying the network, but then it throws a ĭoes anyone know how I can get the account name of an arbitrary file or SID? I don't know much about networking or LDAP or anything. I thought maybe I could do an LDAP lookup on the SID, so I tried the following: string GetNameFromSID( SecurityIdentifier sid )ĭirectoryEntry dirEntry = new DirectoryEntry( str ) However, this does not work for files on a network, presumably because the Translate() function only works with local user accounts. NTAccount ntAccount = (NTAccount)sid.Translate( typeof( NTAccount ) ) I can do this on the local system by getting the SID for the FileInfo object, and then doing: string GetNameFromSID( SecurityIdentifier sid ) I would like to display the account name for each file.

I have a C# application that scans a directory and gathers some information.
