Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect if my program runs in an Active Directory environment?

How do I detect if my program runs in an Active Directory environment?

I'm using C# and .Net 2.0

like image 416
vIceBerg Avatar asked Sep 26 '08 16:09

vIceBerg


People also ask

What is the difference between a domain controller and Active Directory?

A Domain Controller is a server on the network that centrally manages access for users, PCs and servers on the network. It does this using AD. Active Directory is a database that organises your company's users and computers.

What is Active Directory and how is IT used?

Active Directory (AD) is a database and set of services that connect users with the network resources they need to get their work done. The database (or directory) contains critical information about your environment, including what users and computers there are and who's allowed to do what.


2 Answers

Try getting Environment.UserDomainName and comparing it to Environment.MachineName. If the two are the same then it's likely that the user does not have a domain. If they are not the same then the user is logged into a domain which must have a directory server.

like image 178
Captain Toad Avatar answered Oct 22 '22 18:10

Captain Toad


This code will check if the Computer itself is a member of a domain

using System.DirectoryServices.ActiveDirectory;


bool isDomain = false;

try
{
    Domain.GetComputerDomain();
    isDomain = true;
}
catch (ActiveDirectoryObjectNotFoundException)
{
}

However the computer can be in a domain, but the currently logged in user may be a local user account. If you want to check for this use the Domain.GetCurrentDomain() function

like image 25
Ollie Avatar answered Oct 22 '22 19:10

Ollie