Configure DHCP (VBScript)

This code can be found in Chapter 1 of Windows Server 2003 Networking Recipes

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows Server 2003 Networking Recipes"

' This code will configure the local computer
'   to receive its IP configuration from DHCP
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
' --------- END CONFIGURATION ------

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set adapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each adapter In adapters
    errEnable = adapter.EnableDHCP()
    WScript.Echo "Successfully enabled DHCP on interface"
Next

This code has been viewed 2601 times.

New from the creators of TechTasks.com: StatSheet.com