sqlagent007
asked on
Write a VBScript to change the Static IP setting to DHCP
I have a list of hostnames that have Static IP addresses, i would like to get \ write a VBScript that will change the setting on the clinets to DHCP.
Thanks in advance,
Thanks in advance,
This did it for me:
Set Net = Wscript.CreateObject("Wscr ipt.Networ k")
strComputer = ucase(net.computername)
strWMI = "winmgmts:\\" & strComputer & "\root\cimv2"
strQuery = "Select * from Win32_NetworkAdapterConfig uration " & "where IPEnabled=TRUE"
Set objWMIService = GetObject(strWMI)
Set colNetAdapters = objWMIService.ExecQuery(st rQuery)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
errDNS = objNetAdapter.SetDNSServer SearchOrde r(null)
errWINS = objNetAdapter.SetWINSServe r("", "")
RemoveGTW strComputer, objNetAdapter.SettingID
Next
Sub RemoveGTW(strComputer, lsnicsid)
Const HKEY_LOCAL_MACHINE = &H80000002
arrStringValues = Array()
strEntryName = "DefaultGateway"
lsStrWMI = "winmgmts:{impersonationLe vel=impers onate}!\\" & strComputer & "\root\default:StdRegProv"
Set objReg=GetObject(lsStrWMI)
strKeyPath = "SYSTEM\CurrentControlSet\ Services\" & lsNicSid & "\Parameters\Tcpip\"
objReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyP ath, strEntryName,arrStringValu es
strKeyPath = "SYSTEM\CurrentControlSet\ Services\T cpip\Param eters\Inte rfaces\" & lsNicSid
objReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyP ath, strEntryName,arrStringValu es
End Sub
Set Net = Wscript.CreateObject("Wscr
strComputer = ucase(net.computername)
strWMI = "winmgmts:\\" & strComputer & "\root\cimv2"
strQuery = "Select * from Win32_NetworkAdapterConfig
Set objWMIService = GetObject(strWMI)
Set colNetAdapters = objWMIService.ExecQuery(st
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
errDNS = objNetAdapter.SetDNSServer
errWINS = objNetAdapter.SetWINSServe
RemoveGTW strComputer, objNetAdapter.SettingID
Next
Sub RemoveGTW(strComputer, lsnicsid)
Const HKEY_LOCAL_MACHINE = &H80000002
arrStringValues = Array()
strEntryName = "DefaultGateway"
lsStrWMI = "winmgmts:{impersonationLe
Set objReg=GetObject(lsStrWMI)
strKeyPath = "SYSTEM\CurrentControlSet\
objReg.SetMultiStringValue
strKeyPath = "SYSTEM\CurrentControlSet\
objReg.SetMultiStringValue
End Sub
ASKER
sr75, is there a way i can have this script read from a text file for the computer name value?
strComputer = ucase(net.computername)
I would like to create a text file with the 100 or so hostnames, then just have the script go one by one down the list.
Is this possible?
Thanks very much.
strComputer = ucase(net.computername)
I would like to create a text file with the 100 or so hostnames, then just have the script go one by one down the list.
Is this possible?
Thanks very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
WMI reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_reference.asp
EnableStatic method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_reference.asp