3

我正在尝试获取有关当前系统域的一些详细信息。通过使用以下代码,我已经能够找到 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对象上似乎代表它的任何属性。

4

1 回答 1

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);
                }
            }
于 2013-05-21T14:25:36.983 回答