0

目前我正在使用以下方法获取硬件信息(网络适配器、处理器、硬盘)

ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");

我的应用程序是桌面,客户端-服务器(应用程序和数据库安装在服务器上)。此方法获取客户端的信息。有没有办法获取局域网上某个节点的硬件信息 - 我想获取服务器的硬件信息?

4

2 回答 2

0

我想获取服务器的硬件信息?

WMI 可以指向另一台服务器,只要:

  • eserver 暴露 WMI
  • 防火墙不会阻止它。
  • 您的用户帐户拥有其他服务器的权限。

就这么简单。

于 2012-06-06T09:37:53.923 回答
0

这是我用来查询远程主机的子程序(这里我假设我已经在远程计算机上配置了 WMI):

    public string getWMI(string[] parameters)
    {
        string ip = parameters[0];
        string username = parameters[1];
        string password = parameters[2];
        string query = parameters[3];
        string result = "";
        ConnectionOptions options = new ConnectionOptions();
        ManagementScope scope;
        options.Username = username;
        options.Password = password;
        try
        {
            scope = new ManagementScope("\\\\" + ip + "\\root\\cimv2", options);
            scope.Connect();
            if (scope.IsConnected)
            {
                ObjectQuery q = new ObjectQuery(query);
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, q);
                ManagementObjectCollection objCol = searcher.Get();
                foreach (ManagementObject mgtObject in objCol)
                {
                    result = result + mgtObject.GetText(TextFormat.CimDtd20);
                }
            }
            else
            {
            }
        }
        catch (Exception e)
        {
            writeLogFile("WMI Error: " + e.Message);
            writeLog("WMI Error: " + e.Message);
        }
        return result;
    }

In that subroutine I use a direct query such as "select * from Win32_ComputerSystem" but you can use ManagementClass as well.

于 2012-06-06T10:20:34.710 回答