Re: Need help getting the domain SID when given a DC=XXX,DC=YYY,CD



I've got the following code in C#, thanks to your help. It compiled with no
error but I'll see if it works when I get into work tomorrow.
--
Thanks.


"Joe Kaplan (MVP - ADSI)" wrote:

Probably the best thing to do is use the Domain class, but specify the DNS
domain name of the domain you want to find in a DirectoryContext object
instead of getting the current domain. Then, you can use the domain that is
returned in the same way to get the DirectoryEntry and the SID for the
object.

Dim d As Domain = Domain.GetDomain(New
DirectoryContext(DirectoryContextType.Domain, "domain.com"))

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" <Pucca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C2FAEDFB-71FB-4BEB-8DFB-54F053FCF392@xxxxxxxxxxxxxxxx
I shouldn't have given the code for getting the current domain becuase that
is mis-leasding. I'm looking for the dmain ID of a given domain
"DC=XXX,DC=YYY,CD=ZZZ", and not the user's login domain.

What you provided is definitely what I need, thank you. However, can I
use
this code for getting the domain object? If not, then how can I get the
domain object if I have the domain name?

DirectoryEntry curdir = new DirectoryEntry("LDAP://DC =
XXX,
DC=YYY,DC=ZZZ");

--
Thanks.


"Joe Kaplan (MVP - ADSI)" wrote:

If you want to do this with LDAP (which it looks like you do since you
are
using the Domain class), then you could do something like this (you were
almost done!):

Domain curDom = Domain.GetCurrentDomain();
using (DirectoryEntry de = currDom.GetDirectoryEntry())
{
byte[] domSid = (byte[]) de.Properties["objectSid"].Value;
}

If you want a SecurityIdentifier instance, just pass the byte array to
the
appropriate constructor.

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" <Pucca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4E060E9E-A1A5-49A4-AC74-B19ACE0A2E56@xxxxxxxxxxxxxxxx
Hi,
I need to get the DomainSID of a given domain. I am using VS2005
C# and .net 2.0. I would most appreciate it if anyone can point me to
some
code
sample.
Domain curDom = Domain.GetCurrentDomain();

--
Thanks.


--
Thanks.






.



Relevant Pages