我正在尝试获取有关当前系统Domain的一些详细信息。 我已经能够使用以下代码找到Name,DomainMode和ForstMode:
System.DirectoryServices.ActiveDirectory.Domain domain = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain();
Console.WriteLine("Domain: " + domain.Name);
Console.WriteLine("Domain Mode: " + domain.DomainMode);
Console.WriteLine("Forest Mode: " + domain.Forest.ForestMode);
但是,我似乎无法弄清楚如何获取域名描述。我正在寻找的屏幕截图:
关于我如何获得这个的任何建议?我没有在Domain
对象上看到任何似乎代表它的属性。
答案 0 :(得分:3)
想出来。除了描述之外,我还能够使用以下代码获取SID:
using (System.DirectoryServices.ActiveDirectory.Domain domain = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain())
{
using (DirectoryEntry directoryEntry = domain.GetDirectoryEntry())
{
Console.WriteLine("Domain: " + domain.Name);
Console.WriteLine("Domain Mode: " + domain.DomainMode);
Console.WriteLine("Forest Mode: " + domain.Forest.ForestMode);
var sidInBytes = directoryEntry.Properties["objectSID"].Value as byte[];
var sid = new SecurityIdentifier(sidInBytes, 0);
Console.WriteLine("Domain SID: " + sid.ToString());
Console.WriteLine("Description: " + directoryEntry.Properties["description"].Value as string);
}
}