C# 如何确定计算机是否连接到novell eDirectory或Microsoft ActiveDirectory?

C# 如何确定计算机是否连接到novell eDirectory或Microsoft ActiveDirectory?,c#,.net,active-directory,novell,edirectory,C#,.net,Active Directory,Novell,Edirectory,我刚刚在我的应用程序中实现了Novell eDirectory。由于我们的应用程序支持Microsoft ActiveDirectory,因此我希望防止出现诸如“Novell yes/no”之类的附加配置参数 那么,是否有其他方法可以确定计算机是否连接到Microsoft ActiveDirectory或Novell网络?如何连接?通过LDAP?如果是,请查找sAMAccountName,它是Active Directory独有的。AD中的每个用户和组都将具有该属性(这是必需的)。而在eDire

我刚刚在我的应用程序中实现了Novell eDirectory。由于我们的应用程序支持Microsoft ActiveDirectory,因此我希望防止出现诸如“Novell yes/no”之类的附加配置参数


那么,是否有其他方法可以确定计算机是否连接到Microsoft ActiveDirectory或Novell网络?

如何连接?通过LDAP?如果是,请查找sAMAccountName,它是Active Directory独有的。AD中的每个用户和组都将具有该属性(这是必需的)。而在eDirectory中,没有人会拥有它,除非他们奇怪地扩展了eDirectory模式来添加它


RootDSE中可能有某种东西会指示哪个是您的源目录。但是我不确定是否有一个很好的例子。

我想知道计算机是否是Windows域的一部分,您可以获得
Win32\u NTDomain
WMI信息

在powerShell中,它提供:

Get-WmiObject Win32_NTDomain
ClientSiteName          : Default-First-Site-Name
DcSiteName              : Default-First-Site-Name
Description             : DOM
DnsForestName           : dom.fr
DomainControllerAddress : \\192.168.183.100
DomainControllerName    : \\WM2008R2ENT
DomainName              : DOM
Roles                   :
Status                  : OK

根据注释编辑您也可以使用
Win32\u ComputerSystem
WMI类

PS> (Get-WMIObject Win32_ComputerSystem).PartOfDomain
False

根据C#中的说明,您可以通过以下方式获得:

using System;
using System.Collections.Generic;
using System.Text;

using System.Management;

namespace WMIQuery
{
  class WmiQuery
  {
    static void Main(string[] args)
    {
      ManagementObjectSearcher domainInfos = new ManagementObjectSearcher("select * from WIN32_NTDomain");

      foreach (ManagementObject domainInfo in domainInfos.Get())
      {
        Console.WriteLine("Name : {0}", domainInfo.GetPropertyValue("Name"));
        Console.WriteLine("Computer/domain : {0}", domainInfo.GetPropertyValue("Caption"));
        Console.WriteLine("Domain name : {0}", domainInfo.GetPropertyValue("DomainName"));
        Console.WriteLine("Status : {0}", domainInfo.GetPropertyValue("Status"));
      }

      // Edition according to @ScottTx comment you can also use `Win32_ComputerSystem` WMI class

      ManagementObjectSearcher ComputerInfos = new ManagementObjectSearcher("select * from Win32_ComputerSystem");
      foreach (ManagementObject ComputerInfo in ComputerInfos.Get())
      {
        if ((bool)ComputerInfo.GetPropertyValue("PartOfDomain"))
          Console.WriteLine("This computer is part of domain");
        else
          Console.WriteLine("This computer is not part of domain");
      }
    }
  }
}
添加对
System.Management
assembly

的引用“连接到Novell网络”这样的说法比过去含糊得多。如果使用Novell(Netware)客户端的工作站上的用户登录到Netware服务器或提供类似NCP(Netware核心协议)的服务(如linux上的OES)的服务器,则仅当用户当前登录到Edirectory(NDS)时,Edirectory中的“网络地址”属性才应存在


有时,由于客户端有缺陷,如果用户登录,则此属性不存在,但通常可以使用该属性。用户同时登录AD&NDS也是完全正常的。此外,根据配置或使用的Novell产品,工作站本身也可以记录到NDS。

Win32\u ComputerSystem.PartOfDomain返回true/false。两种方法都有效。