您如何找出网络上工作站和服务器之间的区别?

pra*_*tor 5 .net c# networking active-directory

我知道如何使用System.DirectoryServices网络在服务器上获取这些机器.问题是我想忽略网络上的工作站/计算机,只检索服务器.

如果有人说检查操作系统版本,获取Win NT系列操作系统版本号的问题是每个数字可能对应于服务器和非服务器操作系统(例如NT版本6.1同时指向Win 7和Win Server 2008 R2).

这是我的基础测试类:

namespace Project1
{
    class Class1
    {
        public static void Main(string[] args)
        {
             List<string> list = Class1.GetComputersOnNetwork();           
        }

        public static List<string> GetComputersOnNetwork()
        {
            string fileName = "networkcomputers.txt";  

            // Delete the file if it exists.
            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }

            // Create the file.
            System.IO.FileStream fs = System.IO.File.Create(fileName, 1024);

            StreamWriter strwr = new StreamWriter(fs);

            int i = 0;
            List<string> list = new List<string>();
            DirectoryEntry root = new DirectoryEntry("WinNT:");           
            foreach (DirectoryEntry computers in root.Children)
            {                   
                if ((computers.Name != "Schema"))
                {
                    i++;
                    Console.WriteLine("Machine Number " + i + ": " + computers.Name);
                    strwr.WriteLine("Machine Number " + i + ": " + computers.Name);
                    list.Add(computers.Name);
                }           
            }
            return list;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

MNG*_*inn 3

与其去看房产operatingSystemVersion,不如看operatingSystem房产。这将为您提供 SKU 的名称。您需要知道哪些是服务器操作系统版本,哪些不是 - 没有IsServer布尔值。根据它们的命名方式,您可以进行通配符搜索来查找包含字符串“server”的operatingSystemVersion计算机。operatingSystemVersion