gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:16:40 24 4
gpt4 key购买 nike

我知道如何使用 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;
}
}
}

最佳答案

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

关于c# - 您如何找出网络上的工作站和服务器之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11655364/

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