Home All Groups Group Topic Archive Search About
Author
31 May 2005 7:55 AM
Nathan
I am attempting for find the groups that a user is associated with but all
the examples I come across don't work.  I'm unsure as to whether it is due to
permissions on our network or if I'm constructing the path to use incorrectly.

Below is C# code I found that should list the groups for a given user, I've
ommitted the actual values for my network for obvious reasons,  instead I've
used a domain which would be abc.def.net as the domain I am accessing.

Any help on either why this is not working or examples that I can use would
be great.

Nathan

string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
+",cn=users,dc=abc,dc=def,dc=net";
DirectoryEntry oUser;
oUser = new DirectoryEntry(strUserADsPath);
listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);

// Invoke IADsUser::Groups method.
object groups = oUser.Invoke("Groups");
foreach ( object group in (IEnumerable)groups)  
{
    // Get the Directory Entry.
    DirectoryEntry groupEntry  = new DirectoryEntry(group);
    listBox1.Items.Add(groupEntry.Name);
}

Author
31 May 2005 2:15 PM
Joe Kaplan (MVP - ADSI)
That approach won't get you all the groups for the user (nested membership
and primary group will be excluded), but it should work.  What error are you
getting (full stace trace)?

Joe K.

Show quoteHide quote
"Nathan" <Nat***@discussions.microsoft.com> wrote in message
news:965A5908-E59E-493A-8FDB-4B903DDCC67C@microsoft.com...
>I am attempting for find the groups that a user is associated with but all
> the examples I come across don't work.  I'm unsure as to whether it is due
> to
> permissions on our network or if I'm constructing the path to use
> incorrectly.
>
> Below is C# code I found that should list the groups for a given user,
> I've
> ommitted the actual values for my network for obvious reasons,  instead
> I've
> used a domain which would be abc.def.net as the domain I am accessing.
>
> Any help on either why this is not working or examples that I can use
> would
> be great.
>
> Nathan
>
> string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
> +",cn=users,dc=abc,dc=def,dc=net";
> DirectoryEntry oUser;
> oUser = new DirectoryEntry(strUserADsPath);
> listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
>
> // Invoke IADsUser::Groups method.
> object groups = oUser.Invoke("Groups");
> foreach ( object group in (IEnumerable)groups)
> {
> // Get the Directory Entry.
> DirectoryEntry groupEntry  = new DirectoryEntry(group);
> listBox1.Items.Add(groupEntry.Name);
> }
Author
31 May 2005 10:49 PM
Nathan
The error occurs on the line listBox1.Items.Add("Groups to which {0}
belongs:"+ oUser.Name);

Stack trace is as follows

"System.Runtime.InteropServices.COMException (0x80072030): There is no such
object on the server
  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()
  at System.DirectoryServices.DirectoryEntry.get_Name()
  at Groups.Form1.button1_Click(Object sender, EventArgs e) in
c:\\dev\\visual studio projects\\groups\\form1.cs:line 135"

I know our domain is ActiveDirectory as our existing VB6 app uses similar
code to retrieve users groups, what COM object is it trying to get?


Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" wrote:

> That approach won't get you all the groups for the user (nested membership
> and primary group will be excluded), but it should work.  What error are you
> getting (full stace trace)?
>
> Joe K.
>
> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
> news:965A5908-E59E-493A-8FDB-4B903DDCC67C@microsoft.com...
> >I am attempting for find the groups that a user is associated with but all
> > the examples I come across don't work.  I'm unsure as to whether it is due
> > to
> > permissions on our network or if I'm constructing the path to use
> > incorrectly.
> >
> > Below is C# code I found that should list the groups for a given user,
> > I've
> > ommitted the actual values for my network for obvious reasons,  instead
> > I've
> > used a domain which would be abc.def.net as the domain I am accessing.
> >
> > Any help on either why this is not working or examples that I can use
> > would
> > be great.
> >
> > Nathan
> >
> > string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
> > +",cn=users,dc=abc,dc=def,dc=net";
> > DirectoryEntry oUser;
> > oUser = new DirectoryEntry(strUserADsPath);
> > listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
> >
> > // Invoke IADsUser::Groups method.
> > object groups = oUser.Invoke("Groups");
> > foreach ( object group in (IEnumerable)groups)
> > {
> > // Get the Directory Entry.
> > DirectoryEntry groupEntry  = new DirectoryEntry(group);
> > listBox1.Items.Add(groupEntry.Name);
> > }
>
>
>
Author
1 Jun 2005 12:39 AM
Joe Kaplan (MVP - ADSI)
You usually get that error when the DN (the part after the DNS name) you
specified doesn't point to a real object.  Are you sure the DN in your path
is correct?

Joe K.

Show quoteHide quote
"Nathan" <Nat***@discussions.microsoft.com> wrote in message
news:37546518-03D5-470B-8E9F-292E06BBE7A6@microsoft.com...
> The error occurs on the line listBox1.Items.Add("Groups to which {0}
> belongs:"+ oUser.Name);
>
> Stack trace is as follows
>
> "System.Runtime.InteropServices.COMException (0x80072030): There is no
> such
> object on the server
>  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
>  at System.DirectoryServices.DirectoryEntry.Bind()
>  at System.DirectoryServices.DirectoryEntry.get_Name()
>  at Groups.Form1.button1_Click(Object sender, EventArgs e) in
> c:\\dev\\visual studio projects\\groups\\form1.cs:line 135"
>
> I know our domain is ActiveDirectory as our existing VB6 app uses similar
> code to retrieve users groups, what COM object is it trying to get?
>
>
> "Joe Kaplan (MVP - ADSI)" wrote:
>
>> That approach won't get you all the groups for the user (nested
>> membership
>> and primary group will be excluded), but it should work.  What error are
>> you
>> getting (full stace trace)?
>>
>> Joe K.
>>
>> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
>> news:965A5908-E59E-493A-8FDB-4B903DDCC67C@microsoft.com...
>> >I am attempting for find the groups that a user is associated with but
>> >all
>> > the examples I come across don't work.  I'm unsure as to whether it is
>> > due
>> > to
>> > permissions on our network or if I'm constructing the path to use
>> > incorrectly.
>> >
>> > Below is C# code I found that should list the groups for a given user,
>> > I've
>> > ommitted the actual values for my network for obvious reasons,  instead
>> > I've
>> > used a domain which would be abc.def.net as the domain I am accessing.
>> >
>> > Any help on either why this is not working or examples that I can use
>> > would
>> > be great.
>> >
>> > Nathan
>> >
>> > string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
>> > +",cn=users,dc=abc,dc=def,dc=net";
>> > DirectoryEntry oUser;
>> > oUser = new DirectoryEntry(strUserADsPath);
>> > listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
>> >
>> > // Invoke IADsUser::Groups method.
>> > object groups = oUser.Invoke("Groups");
>> > foreach ( object group in (IEnumerable)groups)
>> > {
>> > // Get the Directory Entry.
>> > DirectoryEntry groupEntry  = new DirectoryEntry(group);
>> > listBox1.Items.Add(groupEntry.Name);
>> > }
>>
>>
>>
Author
2 Jun 2005 12:07 PM
Nathan
Joe, sorry to sound thick but which part of the string is the DNS name? 

Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" wrote:

> You usually get that error when the DN (the part after the DNS name) you
> specified doesn't point to a real object.  Are you sure the DN in your path
> is correct?
>
> Joe K.
>
> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
> news:37546518-03D5-470B-8E9F-292E06BBE7A6@microsoft.com...
> > The error occurs on the line listBox1.Items.Add("Groups to which {0}
> > belongs:"+ oUser.Name);
> >
> > Stack trace is as follows
> >
> > "System.Runtime.InteropServices.COMException (0x80072030): There is no
> > such
> > object on the server
> >  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
> >  at System.DirectoryServices.DirectoryEntry.Bind()
> >  at System.DirectoryServices.DirectoryEntry.get_Name()
> >  at Groups.Form1.button1_Click(Object sender, EventArgs e) in
> > c:\\dev\\visual studio projects\\groups\\form1.cs:line 135"
> >
> > I know our domain is ActiveDirectory as our existing VB6 app uses similar
> > code to retrieve users groups, what COM object is it trying to get?
> >
> >
> > "Joe Kaplan (MVP - ADSI)" wrote:
> >
> >> That approach won't get you all the groups for the user (nested
> >> membership
> >> and primary group will be excluded), but it should work.  What error are
> >> you
> >> getting (full stace trace)?
> >>
> >> Joe K.
> >>
> >> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
> >> news:965A5908-E59E-493A-8FDB-4B903DDCC67C@microsoft.com...
> >> >I am attempting for find the groups that a user is associated with but
> >> >all
> >> > the examples I come across don't work.  I'm unsure as to whether it is
> >> > due
> >> > to
> >> > permissions on our network or if I'm constructing the path to use
> >> > incorrectly.
> >> >
> >> > Below is C# code I found that should list the groups for a given user,
> >> > I've
> >> > ommitted the actual values for my network for obvious reasons,  instead
> >> > I've
> >> > used a domain which would be abc.def.net as the domain I am accessing.
> >> >
> >> > Any help on either why this is not working or examples that I can use
> >> > would
> >> > be great.
> >> >
> >> > Nathan
> >> >
> >> > string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
> >> > +",cn=users,dc=abc,dc=def,dc=net";
> >> > DirectoryEntry oUser;
> >> > oUser = new DirectoryEntry(strUserADsPath);
> >> > listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
> >> >
> >> > // Invoke IADsUser::Groups method.
> >> > object groups = oUser.Invoke("Groups");
> >> > foreach ( object group in (IEnumerable)groups)
> >> > {
> >> > // Get the Directory Entry.
> >> > DirectoryEntry groupEntry  = new DirectoryEntry(group);
> >> > listBox1.Items.Add(groupEntry.Name);
> >> > }
> >>
> >>
> >>
>
>
>
Author
2 Jun 2005 10:31 PM
Joe Kaplan (MVP - ADSI)
The ADS Path is basically:
<scheme>://<server>/<object>

scheme is LDAP or GC for LDAP databases.  Server is optional for AD and can
be lots of things like the DNS name of a DC, the DNS name of a domain, an IP
address or a netbios name (or blank if doing serverless binding, which finds
a DC based on the current thread's security context's domain membership).
It can also contain a port if the default port is not right.  The object
part is an LDAP distinguished name or other special identifier known by the
directory.  If it is null, it tries to find the defaultNamingContext.

HTH,

Joe K.

Show quoteHide quote
"Nathan" <Nat***@discussions.microsoft.com> wrote in message
news:E96C3D8B-85E1-4553-9631-55FD9AAD4C78@microsoft.com...
> Joe, sorry to sound thick but which part of the string is the DNS name?
>
> "Joe Kaplan (MVP - ADSI)" wrote:
>
>> You usually get that error when the DN (the part after the DNS name) you
>> specified doesn't point to a real object.  Are you sure the DN in your
>> path
>> is correct?
>>
>> Joe K.
>>
>> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
>> news:37546518-03D5-470B-8E9F-292E06BBE7A6@microsoft.com...
>> > The error occurs on the line listBox1.Items.Add("Groups to which {0}
>> > belongs:"+ oUser.Name);
>> >
>> > Stack trace is as follows
>> >
>> > "System.Runtime.InteropServices.COMException (0x80072030): There is no
>> > such
>> > object on the server
>> >  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
>> >  at System.DirectoryServices.DirectoryEntry.Bind()
>> >  at System.DirectoryServices.DirectoryEntry.get_Name()
>> >  at Groups.Form1.button1_Click(Object sender, EventArgs e) in
>> > c:\\dev\\visual studio projects\\groups\\form1.cs:line 135"
>> >
>> > I know our domain is ActiveDirectory as our existing VB6 app uses
>> > similar
>> > code to retrieve users groups, what COM object is it trying to get?
>> >
>> >
>> > "Joe Kaplan (MVP - ADSI)" wrote:
>> >
>> >> That approach won't get you all the groups for the user (nested
>> >> membership
>> >> and primary group will be excluded), but it should work.  What error
>> >> are
>> >> you
>> >> getting (full stace trace)?
>> >>
>> >> Joe K.
>> >>
>> >> "Nathan" <Nat***@discussions.microsoft.com> wrote in message
>> >> news:965A5908-E59E-493A-8FDB-4B903DDCC67C@microsoft.com...
>> >> >I am attempting for find the groups that a user is associated with
>> >> >but
>> >> >all
>> >> > the examples I come across don't work.  I'm unsure as to whether it
>> >> > is
>> >> > due
>> >> > to
>> >> > permissions on our network or if I'm constructing the path to use
>> >> > incorrectly.
>> >> >
>> >> > Below is C# code I found that should list the groups for a given
>> >> > user,
>> >> > I've
>> >> > ommitted the actual values for my network for obvious reasons,
>> >> > instead
>> >> > I've
>> >> > used a domain which would be abc.def.net as the domain I am
>> >> > accessing.
>> >> >
>> >> > Any help on either why this is not working or examples that I can
>> >> > use
>> >> > would
>> >> > be great.
>> >> >
>> >> > Nathan
>> >> >
>> >> > string strUserADsPath = "LDAP://abc.def.net/cn=" +textBox1.Text
>> >> > +",cn=users,dc=abc,dc=def,dc=net";
>> >> > DirectoryEntry oUser;
>> >> > oUser = new DirectoryEntry(strUserADsPath);
>> >> > listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
>> >> >
>> >> > // Invoke IADsUser::Groups method.
>> >> > object groups = oUser.Invoke("Groups");
>> >> > foreach ( object group in (IEnumerable)groups)
>> >> > {
>> >> > // Get the Directory Entry.
>> >> > DirectoryEntry groupEntry  = new DirectoryEntry(group);
>> >> > listBox1.Items.Add(groupEntry.Name);
>> >> > }
>> >>
>> >>
>> >>
>>
>>
>>