I have a problem with my C# code where I want to display all groups under one specific group, called L_P001xxx.
What I want in the end is that beginning with the group L_P001xxx and I want to display all groups until level 3 and in level 3 I want to display only the users.
I think I have to solve this with a recursion, but it is not working as intended.
Now what I get is this:
First member, called A96XYZ of this group, then the first user of this group, but after that it is stuck and I do not know why.
This is my error message:
{"Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))"}
This is my code:
namespace ADQuery
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry root = new DirectoryEntry(String.Format("WinNT://{0},Computer", "10.18.6.9"), null, null, AuthenticationTypes.Secure);
DirectoryEntry admGroup = root.Children.Find("L_P00142W", "group");
DoForEveryNode(admGroup);
}
static void DoForEveryNode(DirectoryEntry de)
{
object members = de.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
Console.WriteLine(member.Name);
DoForEveryNode(member);
}
}
}
}
I did a little more work and now it is possible for me to read the users of each group but there is still one little problem.
I have this group L_P00142W
, and this group has a Domain Local Groups, called L_ext_P00142W
, and this group I cannot access.
All the other groups are not a problem anymore to read for me, but this group is always ignored. Maybe someone knows what I can do or should do? Here is my code:
namespace ADQuery
{
class Program
{
static void Main(string[] args)
{
//GetUserLocalGroups("L_P00142", "10.18.6.9", "s-gruppe");
DirectoryEntry root = new DirectoryEntry(String.Format("WinNT://{0},Computer", "ip-address"), null, null, AuthenticationTypes.Secure);
DirectoryEntry admGroup = root.Children.Find("L_P00142W", "group");
DoForEveryNode(admGroup);
}
static void DoForEveryNode(DirectoryEntry de)
{
if (de.SchemaClassName == "Group")
{
object members = de.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
if (member.SchemaClassName == "User")
Console.WriteLine("I am a user: " + member.Name);
else
{
Console.WriteLine("I am a group: " + member.Name);
DoForEveryNode(member);
}
}
Console.ReadLine();
}
}
}
}
User contributions licensed under CC BY-SA 3.0