Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerating winNT Users with DirectoryServices

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
GB
I posted this question to the msdn newsgroups but no one there has an answer for me :-( so hopefully a tek-tipper will ;-)

I am using DirectoryServices to find all the members of a
certain NT group and display their properties. The
following code works fine.
Code:
DirectoryEntry directory = new DirectoryEntry("WinNT://" 
+ Environment.MachineName + "/MyGroup");
object members = directory.Invoke("Members", null);
foreach(object member in (IEnumerable) members){
  Console.WriteLine(member.Name);
}
However if I use the same code and try to write out the
NativeGuid or Guid property then for the first object alls well and then on the second pass of the foreach loop I get the following exception.

System.Runtime.InteropServices.COMException: Logon
failure: unknown user name or bad password.

Anyone know why?

I've read soem stuff which suggest that I could need to explicitly rebind to the directory each time but this seems crazy. What I don't understand is why readingh Guid is any different from reading Name?

TIA for any light that can be shed on this one for me.

Cheers Rob


i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Just in case anyone is interested I think I have found out whats going on here. The group in question contains Users from both the local WinNT directory and from a domain level Active Directory. When accessing the Guid property for WinNT accounts all is well. When trying to access the Guid from AD accounts I get the error mentioned. I guess that some properties (name among them) are available for AD users through the NT directory though others such as Guid are only available when connecting directly to AD and hence the permissions error. As the app i'm working on is only interested in local users its not a problem anymore.

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top