"NetConnectionStatus=2 and AdapterType='" + adapterType + "'")
Debes especificar el keyword "WHERE", y luego concatenar con "AND".
"WHERE NetConnectionStatus='2' and AdapterType='" + adapterType + "'")
Por lo demás lo veo bien, si estás usando Windows 8 entonces deberías usar la Class
MSFT_NetAdapter.
Te muestro como lo hice en VB.NET:
Dim QueryFormat As String = _
String.Format( _
"SELECT {0} FROM Win32_NetworkAdapter WHERE AdapterType = '{1}' And NetConnectionStatus = '{2}'", _
"AdapterType,NetConnectionID,NetConnectionStatus", _
"Ethernet 802.3", _
"2" _
)
Dim Query As New ObjectQuery(QueryFormat)
Dim Searcher As New ManagementObjectSearcher(Query)
For Each result As ManagementObject In Searcher.Get
MsgBox(String.Format(" NetConnectionID: {1}{0} NetConnectionStatus: {2}{0} AdapterType: {3}{0}", _
Environment.NewLine & Environment.NewLine, _
result.Item("NetConnectionID"), _
result.Item("NetConnectionStatus"), _
result.Item("AdapterType")))
Try
result.InvokeMethod("Disable", Nothing)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
Traducción a C# (No lo he testeado):
string QueryFormat = string.Format("SELECT {0} FROM Win32_NetworkAdapter WHERE AdapterType = '{1}' And NetConnectionStatus = '{2}'", "AdapterType,NetConnectionID,NetConnectionStatus", "Ethernet 802.3", "2");
ObjectQuery Query
= new ObjectQuery
(QueryFormat
);ManagementObjectSearcher Searcher
= new ManagementObjectSearcher
(Query
);
foreach (ManagementObject result in Searcher.Get) {
Interaction.MsgBox(string.Format(" NetConnectionID: {1}{0} NetConnectionStatus: {2}{0} AdapterType: {3}{0}", Environment.NewLine + Environment.NewLine, result.Item("NetConnectionID"), result.Item("NetConnectionStatus"), result.Item("AdapterType")));
try {
result.InvokeMethod("Disable", null);
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================
Saludos!