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

时间:2023-01-27 12:31:21

I know how to get the machines on a server using the System.DirectoryServices network. The issue is that I would like to ignore workstations/computers on the network and only retrieve servers.

我知道如何使用系统将机器放在服务器上。DirectoryServices网络。问题是我想忽略网络上的工作站/计算机,只检索服务器。

In case someone says to check the OS version, the problem with getting a Win NT family OS version number is that each number may correspond to both a server and non-server OS (such as NT version 6.1 referring both to Win 7 and Win Server 2008 R2).

如果有人说要检查操作系统版本,那么得到Win NT家族OS版本号的问题是,每个数字可能对应于服务器和非服务器操作系统(如NT version 6.1,指的是Win 7和Win server 2008 R2)。

Here is my basic test class:

这是我的基本测试课程:

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;
        }
    }
}

2 个解决方案

#1


2  

Instead of going at the operatingSystemVersion property, look at the operatingSystem property. That'll give you the name of the SKU. You'll need to know which are server OS versions and which aren't - there's no IsServer boolean. Depending on how they're named, you may be able to do a wildcard search on operatingSystemVersion to find computers that have a operatingSystemVersion that contains the string "server".

不是使用operatingSystemVersion属性,而是查看operatingSystem属性。这会给你一个SKU的名字。您需要知道哪些是服务器OS版本,哪些不是——没有IsServer boolean值。根据它们的命名方式,您可以在operatingSystemVersion上进行通配符搜索,以查找具有包含字符串“server”的operatingSystemVersion的计算机。

#2


2  

You can read the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallationType.

您可以阅读注册表键HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallationType。

The key is:

关键是:

  • "Server" if this PC is running Windows Server (e.g. Windows Server 2012).
  • “服务器”,如果此PC正在运行Windows服务器(例如,Windows Server 2012)。
  • "Client" if this PC is running Windows Desktop (e.g. Windows 8.1).
  • “客户端”,如果此PC正在运行Windows桌面(例如Windows 8.1)。

This registry key is quite easy to read using any language such as C#.

使用c#之类的任何语言都可以很容易地读取这个注册表项。

For more info, see article entitled "distinguish between server os and workstation".

有关更多信息,请参阅标题为“区分服务器操作系统和工作站”的文章。

#1


2  

Instead of going at the operatingSystemVersion property, look at the operatingSystem property. That'll give you the name of the SKU. You'll need to know which are server OS versions and which aren't - there's no IsServer boolean. Depending on how they're named, you may be able to do a wildcard search on operatingSystemVersion to find computers that have a operatingSystemVersion that contains the string "server".

不是使用operatingSystemVersion属性,而是查看operatingSystem属性。这会给你一个SKU的名字。您需要知道哪些是服务器OS版本,哪些不是——没有IsServer boolean值。根据它们的命名方式,您可以在operatingSystemVersion上进行通配符搜索,以查找具有包含字符串“server”的operatingSystemVersion的计算机。

#2


2  

You can read the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallationType.

您可以阅读注册表键HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallationType。

The key is:

关键是:

  • "Server" if this PC is running Windows Server (e.g. Windows Server 2012).
  • “服务器”,如果此PC正在运行Windows服务器(例如,Windows Server 2012)。
  • "Client" if this PC is running Windows Desktop (e.g. Windows 8.1).
  • “客户端”,如果此PC正在运行Windows桌面(例如Windows 8.1)。

This registry key is quite easy to read using any language such as C#.

使用c#之类的任何语言都可以很容易地读取这个注册表项。

For more info, see article entitled "distinguish between server os and workstation".

有关更多信息,请参阅标题为“区分服务器操作系统和工作站”的文章。