예제 #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);

            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();
                    //}
                    if (adapter.AdapterType.Equals("Wireless"))
                    {
                        adapter.Enable();
                    }
                }
            }
        }
        public static void EnableNetworkAdapter()
        {
            SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=0");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);

            foreach (ManagementObject mo in search.Get())
            {
                // Used "mgmtclassgen Win32_NetworkAdapter -p NetworkAdapter.cs" to generate the NetworkAdapter class.
                NetworkAdapter adapter = new NetworkAdapter(mo);
                adapter.Enable();
            }
        }
예제 #3
0
 /// <summary>
 /// Restarts a given Network adapter
 /// </summary>
 /// <param name="nicDescription">The full description of the network interface class</param>
 public static void RestartNetworkAdapter(string nicDescription)
 {
     using (ManagementClass networkConfigMng = new ManagementClass("Win32_NetworkAdapter"))
     {
         using (ManagementObjectCollection networkConfigs = networkConfigMng.GetInstances())
         {
             foreach (ManagementObject mboDNS in networkConfigs.Cast <ManagementObject>().Where(mo => (string)mo["Description"] == nicDescription))
             {
                 // NA class was generated by opening dev console and entering
                 // mgmtclassgen Win32_NetworkAdapter -p NetworkAdapter.cs
                 using (NetworkAdapter adapter = new NetworkAdapter(mboDNS))
                 {
                     adapter.Disable();
                     adapter.Enable();
                     Thread.Sleep(4000); // Wait 5 secs until exiting, will give enough time to re-connect
                     return;
                 }
             }
         }
     }
 }
        private static void RestartAdapter()
        {
            Console.WriteLine("Restarting Adapters...");
            SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);
            ArrayList threads = new ArrayList();

            foreach (ManagementObject result in search.Get())
            {
                Thread t = new Thread(() =>
                {
                    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.Disable();
                        Console.WriteLine("Waiting " + MillisecondsTimeoutDC / 1000 + " seconds to activate the card.");
                        Thread.Sleep(MillisecondsTimeoutDC);
                        adapter.Enable();
                        Console.WriteLine("Waiting " + MillisecondsTimeoutC / 1000 +
                                          " seconds in order to get the card ready.");
                        Thread.Sleep(MillisecondsTimeoutC);
                    }
                });
                t.Start();
                threads.Add(t);
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }
        }
예제 #5
0
 public override async Task EnableNetwork()
 {
     await network.Enable(new Network.EnableCommandSettings());
 }