We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Set ethernet adapter to DHCP in Visual Basic application

Medium Priority
Last Modified: 2012-08-13

I need to be able to set an ethernet adapter to DHCP in a visual basic application,

Is anyone able to assist?

Watch Question

This can be easily done with Windows Management Instrumentation (WMI)...  The toughest part is figuring out which network adpater (there will be several psuedo adapters) to use.   In the example below, it turns on DHCP for all adapters that support IP.

Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
    Public Class CallWMIMethod
        Public Overloads Shared Function Main() As Integer
                Dim classInstance As New ManagementObject( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 
                ' Execute the method and obtain the return values.
                Dim outParams As ManagementBaseObject = _
                    classInstance.InvokeMethod("EnableDHCP", Nothing, Nothing)
                ' List outParams
                Console.WriteLine("Out parameters:")
                Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))
            Catch err As ManagementException
                MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message)
            End Try
        End Function
    End Class
End Namespace

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.