Home All Groups Group Topic Archive Search About

How to retrieve the domain name for an AD user object?

Author
20 Dec 2006 2:06 AM
Pucca
Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000. 

I have a User's SID in SDDL format and also a DIRECTORYENTRY object
representing this user object.  How can I retrieve the name of the domain
that this user object belongs to? 
--
Thanks.

Author
20 Dec 2006 2:52 AM
Joe Kaplan
Probably the easiest way is create a SecurityIdentifier object and convert
it to an NTAccount with the Translate method.  You could also get the prefix
of the SID and query AD to find the domainDNS object that has that SID.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Show quoteHide quote
"Pucca" <Pu***@discussions.microsoft.com> wrote in message
news:9E97300B-C2AC-460B-B8F6-5AFDBA8BC418@microsoft.com...
> Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.
>
> I have a User's SID in SDDL format and also a DIRECTORYENTRY object
> representing this user object.  How can I retrieve the name of the domain
> that this user object belongs to?
> --
> Thanks.
Author
20 Dec 2006 3:25 AM
Pucca
Hi Joe,

This is what I got so far.  I need to get the domain name in a string.  How
can I do that from here?  thank you.

//sid = S-1-5-21-1993962763-879983540-725345543-500
            SecurityIdentifier sdSID = new SecurityIdentifier(sid);
            string domainSid = sdSID.AccountDomainSid.Value.ToString();
            SecurityIdentifier domain = new SecurityIdentifier(domainSid);

--
Thanks.


Show quoteHide quote
"Joe Kaplan" wrote:

> Probably the easiest way is create a SecurityIdentifier object and convert
> it to an NTAccount with the Translate method.  You could also get the prefix
> of the SID and query AD to find the domainDNS object that has that SID.
>
> Joe K.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"
> http://www.directoryprogramming.net
> --
> "Pucca" <Pu***@discussions.microsoft.com> wrote in message
> news:9E97300B-C2AC-460B-B8F6-5AFDBA8BC418@microsoft.com...
> > Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.
> >
> > I have a User's SID in SDDL format and also a DIRECTORYENTRY object
> > representing this user object.  How can I retrieve the name of the domain
> > that this user object belongs to?
> > --
> > Thanks.
>
>
>
Author
20 Dec 2006 5:02 AM
Joe Kaplan
NTAccount account = domain.Translate(typeof(NTAccount));

Alternately, you could just translate the user SID and parse out the domain
name.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Show quoteHide quote
"Pucca" <Pu***@discussions.microsoft.com> wrote in message
news:B4416024-1E01-4507-A298-E421AD3764DF@microsoft.com...
> Hi Joe,
>
> This is what I got so far.  I need to get the domain name in a string.
> How
> can I do that from here?  thank you.
>
> //sid = S-1-5-21-1993962763-879983540-725345543-500
>            SecurityIdentifier sdSID = new SecurityIdentifier(sid);
>            string domainSid = sdSID.AccountDomainSid.Value.ToString();
>            SecurityIdentifier domain = new SecurityIdentifier(domainSid);
>
> --
> Thanks.
>
>
> "Joe Kaplan" wrote:
>
>> Probably the easiest way is create a SecurityIdentifier object and
>> convert
>> it to an NTAccount with the Translate method.  You could also get the
>> prefix
>> of the SID and query AD to find the domainDNS object that has that SID.
>>
>> Joe K.
>>
>> --
>> Joe Kaplan-MS MVP Directory Services Programming
>> Co-author of "The .NET Developer's Guide to Directory Services
>> Programming"
>> http://www.directoryprogramming.net
>> --
>> "Pucca" <Pu***@discussions.microsoft.com> wrote in message
>> news:9E97300B-C2AC-460B-B8F6-5AFDBA8BC418@microsoft.com...
>> > Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.
>> >
>> > I have a User's SID in SDDL format and also a DIRECTORYENTRY object
>> > representing this user object.  How can I retrieve the name of the
>> > domain
>> > that this user object belongs to?
>> > --
>> > Thanks.
>>
>>
>>
Author
20 Dec 2006 7:23 PM
Pucca
Goody, that worked great!  Thank you very much Joe.
--
Thanks.


Show quoteHide quote
"Joe Kaplan" wrote:

> NTAccount account = domain.Translate(typeof(NTAccount));
>
> Alternately, you could just translate the user SID and parse out the domain
> name.
>
> Joe K.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"
> http://www.directoryprogramming.net
> --
> "Pucca" <Pu***@discussions.microsoft.com> wrote in message
> news:B4416024-1E01-4507-A298-E421AD3764DF@microsoft.com...
> > Hi Joe,
> >
> > This is what I got so far.  I need to get the domain name in a string.
> > How
> > can I do that from here?  thank you.
> >
> > //sid = S-1-5-21-1993962763-879983540-725345543-500
> >            SecurityIdentifier sdSID = new SecurityIdentifier(sid);
> >            string domainSid = sdSID.AccountDomainSid.Value.ToString();
> >            SecurityIdentifier domain = new SecurityIdentifier(domainSid);
> >
> > --
> > Thanks.
> >
> >
> > "Joe Kaplan" wrote:
> >
> >> Probably the easiest way is create a SecurityIdentifier object and
> >> convert
> >> it to an NTAccount with the Translate method.  You could also get the
> >> prefix
> >> of the SID and query AD to find the domainDNS object that has that SID.
> >>
> >> Joe K.
> >>
> >> --
> >> Joe Kaplan-MS MVP Directory Services Programming
> >> Co-author of "The .NET Developer's Guide to Directory Services
> >> Programming"
> >> http://www.directoryprogramming.net
> >> --
> >> "Pucca" <Pu***@discussions.microsoft.com> wrote in message
> >> news:9E97300B-C2AC-460B-B8F6-5AFDBA8BC418@microsoft.com...
> >> > Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.
> >> >
> >> > I have a User's SID in SDDL format and also a DIRECTORYENTRY object
> >> > representing this user object.  How can I retrieve the name of the
> >> > domain
> >> > that this user object belongs to?
> >> > --
> >> > Thanks.
> >>
> >>
> >>
>
>
>