如何确定计算机是否连接到 novell eDirectory 或Microsoft ActiveDirectory
本文关键字:eDirectory Microsoft ActiveDirectory novell 何确定 计算机 是否 连接 | 更新日期: 2023-09-27 17:56:21
我刚刚在我的应用程序中实现了Novell eDirectory。由于我们的应用程序支持Microsoft ActiveDirectory,我想防止额外的配置参数,如"Novell yes/no"。
那么,有没有另一种方法可以确定计算机是否连接到Microsoft ActiveDirectory或Novell网络?
我想知道计算机是否是Windows域的一部分,您可以获得Win32_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
根据@ScottTx注释的版本,您也可以使用Win32_ComputerSystem
WMI类
PS> (Get-WMIObject Win32_ComputerSystem).PartOfDomain
False
根据 C# 中的类文档Win32_NTDomain您可以通过以下方式获取它:
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
引用
像"连接到Novell网络"这样的陈述比以前要模糊得多。 如果使用Novell(Netware)客户端的工作站上的用户登录到网络软件服务器或提供NCP(Netware Core Protocol)的服务器,例如linux上的OES,则仅当用户当前登录到EDirectory(NDS)时,Edirectory中的网络地址属性才应存在。
有时由于客户端有缺陷,如果用户登录,此属性不存在,但通常您可以使用该属性。此外,用户同时登录AD和NDS也是完全正常的。此外,工作站本身也可以记录到 NDS,具体取决于配置或正在使用的 Novell 产品。
你是如何连接的? 通过LDAP? 如果是这样,请查找 sAMAccountName,这是 Active Directory 独有的。 AD 中的每个用户和组都将具有该属性(这是必需的)。 而在 eDirectory 中,没有人会拥有它,除非他们奇怪地扩展了 eDirectory 架构来添加它。
RootDSE 中可能有一些内容会指示哪个是您的源目录。 但我不确定一个很好的例子。