I had a problem when I need to turn on an already disabled card, and the crawler in the WMI NetworkAdapter does not return an object.
I can think of a possible way to do this, but I was not able to get it to work, i.e. create a managementObject using this as the name of the constructor. but it only throws exceptions
{\\.\root\CIMV2:Win32_NetworkAdapter.NetConnectionID='Wireless Network Connection'}
Another way was to shell netsh and turn on the device, which is ugly, or use shell32 / dll "Enable" to do the same, again, both only pass the name. I got the name from a registry scan on HKLM\SYSTEM\CurrentControlSet\Network and looked for MediaType = 2 to get a list of strings of wireless devices. Everything is fine if I launch the application when the adapter is turned on, since I can get the network object for the wireless device, but it all crashes if the application starts when the wireless device is disconnected.
thanks
Edit: this is a code that I would love to work, but not go: (
using System; using System.Management; class Sample { public static int Main(string[] args) { ManagementObject mObj = new ManagementObject("\\\\.\\root\\CIMV2:Win32_NetworkAdapter.NetConnectionID=\"Wireless Network Connection\""); mObj.InvokeMethod("Enable", null); return 0; } }
source share