Re: Accessing SAM database using C#

From: Ollie (ollie_riches_at_NO_SPAMhotmail.com)
Date: 05/12/03


Date: Mon, 12 May 2003 11:18:23 +0100


Jim,

try this....

System.DirectoryServices.DirectoryEntry obDirEntry = new
System.DirectoryServices.DirectoryEntry("WinNT://" + "FB2");
System.DirectoryServices.DirectoryEntries entries = obDirEntry.Children;
System.DirectoryServices.DirectoryEntry obUser = entries.Find("testUser");
string name = obUser.Name;
System.DirectoryServices.PropertyCollection properties = obUser.Properties;
bool valid = properties.Contains("FullName");
string fullName = "";
System.DirectoryServices.PropertyValueCollection pvc = null;
if(valid)
{
pvc = properties["FullName"];
fullName = (string)pvc.Value;
}

"Jim" <jim@jimmmm.com> wrote in message
news:O8SOupGGDHA.2248@TK2MSFTNGP10.phx.gbl...
> High I want to search for a user account that is stored in local or domain
> SAM database, I have been able to search against Active Directory but
would
> like to be able to do the same against the SAM database using the
> System.DirectoryServices namespace?
>
> Can anyone provide me with a sample or tell me why the following does not
?
>
> System.DirectoryServices.DirectoryEntry dirRoot = new
> System.DirectoryServices.DirectoryEntry("WinNT://localhost");
>
> string nameContext =
> dirRoot.Invoke("GET","defaultNamingContext").ToString();
>
> System.DirectoryServices.DirectoryEntry dirRootPath = null;
> dirRootPath = new System.DirectoryServices.DirectoryEntry("WinNT://"+
> m_nameContext);
>
> System.DirectoryServices.DirectorySearcher dirSearcher = new
> System.DirectoryServices.DirectorySearcher(dirRootPath);
>
> dirSearcher.Filter = m_SAMAccountName + username;
> System.DirectoryServices.SearchResultCollection dirResults =
> dirSearcher.FindAll();
> if(dirResults.Count != 1)
> return null;
> ....
> ....
>
> Cheers
>
> Jim
>
>