• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Set ethernet adapter to DHCP in Visual Basic application

Hi,

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

Is anyone able to assist?

Thanks,
0
locdang
Asked:
locdang
1 Solution
 
grayeCommented:
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

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now