Set ethernet adapter to DHCP in Visual Basic application

Posted on 2009-02-09
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?

Question by:locdang
    1 Comment
    LVL 41

    Accepted Solution

    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


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now