gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:16:07 30 4
gpt4 key购买 nike

我刚刚在我的应用程序中实现了 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

根据 Win32_NTDomain class documentation在 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 程序集的引用

关于c# - 如何确定计算机是否连接到 novell eDirectory 或 Microsoft ActiveDirectory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5964390/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com