Jul
19
How To Enable DHCP Completely?
Wednesday, 19. July 2006 16:12
The Sub procedure below uses WMI in order to set the network adapter’s IP configuration to DHCP, not only for IP address, IP gateway, and subnet mask, but also for both DNS server search order and WINS servers:
Sub AutoIpConfig
Const LOCAL_MACHINE = "."
Dim objWmi, colItems, objItem, intError
Set objWmi =WshGetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& LOCAL_MACHINE & "\root\cimv2")
Set colItems = objWmi.ExecQuery( _
"Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objItem In colItems
intError = objItem.EnableDHCP()
If (intError <> 0) Then
CriticalErrorBox "Could not enable DHCP."
End If
objItem.SetDNSServerSearchOrder Null
objItem.SetWINSServer Null, Null
Exit For
Next
End Sub
If you omit the SetDNSServerSearchOrder and SetWINSServer statements the previously configured DNS and WINS servers will remain in the network adapter’s IP configuration.
Category:Scripting, VBScript | Comment (0) | Author: Frank-Peter