Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a Active Directory server is up and running using .Net?

Before trying to query the AD server I would like to check if it is alive and kicking. Looks like a trivial thing, but I haven´t found anything to elucidate this.

How can I do that?

like image 362
Seiti Avatar asked Nov 27 '08 19:11

Seiti


People also ask

How do I check AD configuration?

Open the Server Manager, go to the Tools menu and select Active Directory Users and Computers. Expand the domain and click Users. Right-click on the right pane and press New > User. When the New Object-User box displays enter a First name, Last name, User logon name, and click Next.

How do I know if a domain controller is installed?

Thoroughly test the domain controller for all directory service issues, you can run the dcdiag /v command. The output of this command provides detailed information about the conditions on the domain controller. SysVol folder will be displayed if the Active Directory is installed.


1 Answers

I just try to get the current domain context associated with the running user:

try {
    var domain = Domain.GetCurrentDomain();
    /* Whatever i need from the domain */
} catch(ActiveDirectoryOperationException ex) {
    MessageBox.Show("Cannot contact AD Server");
}

If you want to connect to another domain you can try:

try {
    var domain = Domain.GetDomain(
        new DirectoryContext(DirectoryContextType.Domain, "mydomain.local"));
    /* Whatever i need from the domain */
} catch(ActiveDirectoryOperationException ex) {
    MessageBox.Show("Cannot contact AD Server");
}
like image 118
Yona Avatar answered Sep 29 '22 17:09

Yona