如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? [英] How to check if a Active Directory server is up and running using .Net?

查看:19
本文介绍了如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试查询 AD 服务器之前,我想检查它是否还活着并且正在运行.看起来是一件微不足道的事情,但我还没有找到任何可以解释这一点的东西.

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.

我该怎么做?

推荐答案

我只是尝试获取与正在运行的用户关联的当前域上下文:

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");
}

这篇关于如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆