2
我試圖通過傳遞主機名來獲得networkadtapter配置,如ipaddress,IPSubnet,WINSPrimaryServer,WINSSecondaryServer。通過WMI獲取Networkadatper配置時出現「無效查詢類型」錯誤
但它引發以下錯誤
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);
}
代碼,請幫我在這
感謝哥們!對我的疏忽抱歉 –