我知道如何使用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?例如,您可以使用RPC查詢遠程計算機的註冊表。 – mellamokb 2012-07-25 17:36:35
「服務器」是指「運行Windows的服務器SKU」,而不是任何特定類型的行爲或已安裝的服務? – MNGwinn 2012-07-25 18:01:58
mellamokb 我會研究一下。 @MNGwinn 是的,這就是我所指的。 – praetor 2012-07-25 18:12:00