views:

10

answers:

0

Hi,

I need to (des)activate network card so that there's no wired ("secured") and wireless wifi,3g active connections at the same time.

So, I need to tell apart which connexions is wireless and which is wired. I see no obvious way to do it querying the Win32_NetworkAdapter. Plus there a lot of (?)virtual(?) devices I really don't care about.

Do you know what to query (and with which filters) to get a list of pertinent connexions = list of connexions [Ethernet, WIFI, 3G or bluetooth] which I need to en/disable and dhcplease ?

I looked over the net and the solution seems to be querying [root/wmi/]MSNdis_80211_Configuration so I wrote the following

 System.Management.ManagementObjectSearcher VLOB_80211 = new System.Management.ManagementObjectSearcher("root\\wmi", "Select * From MSNdis_80211_Configuration");
                ManagementObjectCollection wireless = VLOB_80211.Get(); // <-- error
                    foreach (ManagementObject wconn in wireless)
                    {
                        string VLST_INAME = wconn["InstanceName"].ToString(); 
                        System.Management.ManagementObjectSearcher VLOB_CONNE = new System.Management.ManagementObjectSearcher("root\\cimv2", "Select * From Win32_NetworkAdapter Where Name = '%InstanceName%'".Replace("%InstanceName%",""));
                        ManagementObjectCollection VLOB_CONNX = VLOB_CONNE.Get();

                            foreach (ManagementObject obj in VLOB_CONNX)
                            {
                                // do stuff such as obj.InvokeMethod("ReleaseDHCPLease", null);
                            }
                    }

This doesn't work. depending on the PC I get a feature not supported [8004100c] or an empty list.

Any pointer, ideas, tests, urls ?