无效的查询类型"通过WMI获取网络适配器配置时出现错误
本文关键字:配置 网络适配器 获取 错误 WMI 通过 查询 类型 quot 无效 | 更新日期: 2023-09-27 18:09:05
我试图通过传递主机名来获得网络适配器配置,如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);
}
请帮我一下
按如下方式更改查询
query = new ObjectQuery(String.Format("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName='{0}'", objServerInfo.DNSHostName));