2

我正在尝试通过传递主机名来获取网络适配器配置,例如 ipaddress、IPSubnet、WINSPrimaryServer、WINSSecondaryServer。

但它会引发以下错误

System.Management.ManagementStatus.InvalidQueryType

以下是我使用过的代码

query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName='{0}'", objServerInfo.DNSHostName);
                    searcher = new ManagementObjectSearcher(mgmtScope, query);
                    ManagementObjectCollection networkConfigresults = searcher.Get();
                    foreach (ManagementObject queryObj in networkConfigresults)
                    {
                        NetworkConfig objNetworkConfig = new NetworkConfig();
                        objNetworkConfig.serverId = sysconfig.SystemId;
                        objNetworkConfig.IPAdresss =  queryObj["IPAddress"] != null ? String.Join(",", (string[])queryObj["IPAddress"]) : string.Empty;
                        objNetworkConfig.subnetMask = queryObj["IPSubnet"] != null ? String.Join(",", (string[])queryObj["IPSubnet"]) : string.Empty;
                        objNetworkConfig.primaryDNSServer = Convert.ToString(queryObj["WINSPrimaryServer"]);
                        objNetworkConfig.alternateDNSServer = Convert.ToString(queryObj["WINSSecondaryServer"]);
                        lstNetworkConfig.Add(objNetworkConfig);
                    }

请帮助我

4

1 回答 1

2

更改您的查询如下

query = new ObjectQuery(String.Format("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName='{0}'", objServerInfo.DNSHostName));
于 2013-04-15T07:54:45.137 回答