Thursday, September 27, 2007

VBScript to assign DHCP ip address

'Script Start

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = true")


Sub goDHCP()
For Each objItem In colItems

errEnable = objItem.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Wscript.Echo "DHCP could not be enabled."
End If
Msgbox "setting DNS"
errDNS = objitem.SetDNSServerSearchOrder()
errDDNS = objItem.SetDynamicDNSRegistration
msgbox "DNS Set"
errRenew = objItem.RenewDHCPLease
msgbox "renew called"
If errRenew = 0 Then
Wscript.Echo "DHCP lease renewed."
Wscript.Echo "DHCP lease could not be renewed." & err.number & err.description
End If
End Sub

'Script End

Got from website

How to execute a VBScript

No comments: