How do I get the domain name that a computer is on?

M

Mark Rae

In the case of NETWORD SERVICE the env var USERDOMAIN is an empty string.
And
there are cases where I do not have a client user (scheduled reports) so I
can't use the domain part of an authenticated user.

Obviously, it's easy enough to get the machine name of the IIS server, but
to return the name of the domain that it's part of I think you'd have to use
ActiveDirectory...
 
M

Mark Rae

Any idea how? I've tried and this seems to be a very difficult problem.

E, well this certainly works for me:

using (DirectorySearcher objSearcher = new DirectorySearcher())
{
strDomain = objSearcher.SearchRoot.Name.Substring(3);
}
 
M

Mark Rae

Is (string) objSearcher.SearchRoot.Properties["name"].Value;

legit (ie will always work)? Or better to use yours below? I want to make
sure whatever I use works on 100% of the system configurations out there.

Sorry, but I don't know enough about it to be sure.

I suggest you post in microsoft.public.adsi.general - anything you are told
by Joe Kaplan you can take as gospel... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top