G
Guest
i want to get the first name of the logged in user on the current machine,
windows application
i used the following code but i get System.NullReferenceException when it
reaches the Console.Writeline line
string myADSPath = "LDAP://myadelaide.com/CN=Users,DC=myadelaide,DC=com" ;
DirectoryEntry myDirectoryEntry = new DirectoryEntry(myADSPath);
DirectoryEntry mySearchRoot = new DirectoryEntry(myADSPath);
DirectorySearcher myDirectorySearcher =new DirectorySearcher(mySearchRoot);
myDirectorySearcher.Filter="(objectClass=user)";
SearchResult mySearchResult = myDirectorySearcher.FindOne();
myDirectoryEntry.Name
if ( mySearchResult != null )
{
myDirectoryEntry =mySearchResult.GetDirectoryEntry();
Console.WriteLine(myDirectoryEntry.Properties["First
name"].Value.ToString() );
}
though i can get the DirectoryEntry.Name but any other-
DirectoryEntry.Properties["Property name"]- dosen't work though the property
count is 35 when i put DirectoryEntry.Properties into quick watch.
any help please
windows application
i used the following code but i get System.NullReferenceException when it
reaches the Console.Writeline line
string myADSPath = "LDAP://myadelaide.com/CN=Users,DC=myadelaide,DC=com" ;
DirectoryEntry myDirectoryEntry = new DirectoryEntry(myADSPath);
DirectoryEntry mySearchRoot = new DirectoryEntry(myADSPath);
DirectorySearcher myDirectorySearcher =new DirectorySearcher(mySearchRoot);
myDirectorySearcher.Filter="(objectClass=user)";
SearchResult mySearchResult = myDirectorySearcher.FindOne();
myDirectoryEntry.Name
if ( mySearchResult != null )
{
myDirectoryEntry =mySearchResult.GetDirectoryEntry();
Console.WriteLine(myDirectoryEntry.Properties["First
name"].Value.ToString() );
}
though i can get the DirectoryEntry.Name but any other-
DirectoryEntry.Properties["Property name"]- dosen't work though the property
count is 35 when i put DirectoryEntry.Properties into quick watch.
any help please