【发布时间】:2012-07-25 17:33:41
【问题描述】:
我知道如何使用 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;
}
}
}
【问题讨论】:
-
服务器上是否启用了 RPC 并且您的应用程序可以访问?例如,您可以使用 RPC 查询远程机器的注册表。
-
“服务器”是指“运行 Windows 的服务器 SKU”,而不是任何特定类型的行为或安装的服务?
-
mellamokb 我会调查的。 @MNGwinn 是的,这就是我所指的。
-
您在域中吗?您是否考虑过为此使用 Active Directory?
-
我正在为此使用 Active Directory。我需要做的是按操作系统区分服务器和工作站。问题是没有操作系统属性。
标签: c# .net networking active-directory