private void Button_Click(object sender, RoutedEventArgs e) { SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2"); ManagementObjectSearcher search = new ManagementObjectSearcher(query); uint c = 100; for (int i = 1; i <= 12; i++) { query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=" + i.ToString()); search = new ManagementObjectSearcher(query); foreach (ManagementObject result in search.Get()) { NetworkAdapter adapter = new NetworkAdapter(result); // Identify the adapter you wish to disable here. // In particular, check the AdapterType and // Description properties. // Here, we're selecting the LAN adapters. //if (adapter.AdapterType.Equals("Ethernet 802.3")) //{ // adapter.Enable(); //} MessageBox.Show(adapter.AdapterType.ToString() + ": " + adapter.Name.ToString()); if (adapter.NetConnectionStatus == 2) { c = adapter.Disable(); } MessageBox.Show(adapter.NetConnectionStatus.ToString() + " " + c.ToString()); } } }
public NetworkAdapter(ManagementScope mgmtScope, string keyDeviceID) { this.InitializeObject(((ManagementScope)(mgmtScope)), new ManagementPath(NetworkAdapter.ConstructPath(keyDeviceID)), null); }
public NetworkAdapter(string keyDeviceID) { this.InitializeObject(null, new ManagementPath(NetworkAdapter.ConstructPath(keyDeviceID)), null); }