2013-04-15 74 views
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); 
        } 

代碼,請幫我在這

回答

2

更改您的查詢如下

query = new ObjectQuery(String.Format("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName='{0}'", objServerInfo.DNSHostName)); 
+1

感謝哥們!對我的疏忽抱歉 –

相關問題