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

  • Thread starter Thread starter Guest
  • Start date Start date
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...
 
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);
}
 
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... :-)
 
Back
Top