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

x

Set ethernet adapter to DHCP in Visual Basic application

Medium Priority
183 Views
Last Modified: 2012-08-13
Hi,

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

Is anyone able to assist?

Thanks,
Comment
Watch Question

Commented:
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.
http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa390378(VS.85).aspx 

Imports System
Imports System.Management
Imports System.Windows.Forms
 
Namespace WMISample
    Public Class CallWMIMethod
        Public Overloads Shared Function Main() As Integer
            Try
                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.

OR

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.