How to define user's first an last names?

E

Evgeny Zoldin

Hi, ALL

I have user's Windows logon username - DOMAIN_NAME\Username
Then using classes DirectoryEntry and DirectorySeacher I can get from
domain's Active Directory user's first and last names and aother properties
of its profile by means of the following:

DirectoryEntry rootEntry = new DirectoryEntry("GC://rootDSE");
string domainPath =
rootEntry.Properties["defaultNamingContext"][0].ToString();
DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainPath);
DirectorySearcher searcher = new DirectorySearcher(domain);
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectClass=user)(name=" + username + "))"; //
username without domain name
SearchResult res = searcher.FindOne();
if( res != null ) return res.GetDirectoryEntry();
else return null;

But still I don't know how to obtain users properties if user has only local
account on WindowsXP machine, but not Domain account. What the LDAP path to
Activy Directory of this local WinXP computer while computer is member of
Domain itself, but user is local user only?

Thanx
Evgeny
 
P

Paul Clement

¤ Hi, ALL
¤
¤ I have user's Windows logon username - DOMAIN_NAME\Username
¤ Then using classes DirectoryEntry and DirectorySeacher I can get from
¤ domain's Active Directory user's first and last names and aother properties
¤ of its profile by means of the following:
¤
¤ DirectoryEntry rootEntry = new DirectoryEntry("GC://rootDSE");
¤ string domainPath =
¤ rootEntry.Properties["defaultNamingContext"][0].ToString();
¤ DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainPath);
¤ DirectorySearcher searcher = new DirectorySearcher(domain);
¤ searcher.SearchScope = SearchScope.Subtree;
¤ searcher.Filter = "(&(objectClass=user)(name=" + username + "))"; //
¤ username without domain name
¤ SearchResult res = searcher.FindOne();
¤ if( res != null ) return res.GetDirectoryEntry();
¤ else return null;
¤
¤ But still I don't know how to obtain users properties if user has only local
¤ account on WindowsXP machine, but not Domain account. What the LDAP path to
¤ Activy Directory of this local WinXP computer while computer is member of
¤ Domain itself, but user is local user only?
¤

Have you tried using the WinNT provider instead?

Dim ADEntry As New DirectoryEntry("WinNT://<machinename>/<user>")


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top