VBSCRIPT To change Ipconfiguration to Obtain an IP address automatically

Vicki05
Vicki05 used Ask the Experts™
on
I found a batch file that resets the network adapter settings. Can someone please convert this to vbscript? Or if someone already has a solution? I need to change the TCP/IP settings to Obtain an IP address automatically and Obtain DNS server address automatically? Can someone please help.


Here is the batch file

@echo off
:prompt
color 1f
cls
echo NETWORK RESET SCRIPT

:test
cls
echo —————————————————-
echo - RELEASING IP…. -
echo —————————————————-
ipconfig /release >nul
echo.
echo Done!
echo.
echo —————————————————-
echo - RESETTING IP LOG… -
echo —————————————————-
@netsh int ip reset C:\Windows\TEMP\IPRESETLOG.txt >nul
echo.
echo Done!
echo.
echo —————————————————-
echo - FLUSHING ARP TABLES… -
echo —————————————————-
@arp -d >nul
echo.
echo Done!
echo.
echo —————————————————-
echo - FLUSHING DNS… -
echo —————————————————-
@ipconfig /flushdns >nul
echo.
echo Done!
echo.
echo —————————————————-
echo - RENEWING IP… -
echo —————————————————-
@ipconfig /renew >nul
echo.
echo Done!
echo.
cls
echo —————————————————-
echo Heres Your Status: -
echo —————————————————-
ipconfig /all
pause
echo.
cls
exit


Please help.
Vicki
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I just searched your question's title on google and found this:
http://support.microsoft.com/kb/197424
 - switch to DHCP from VBScript.

Author

Commented:
I just tried it, it does not reset the ipconfiguration to automatic.
Most Valuable Expert 2013
Top Expert 2013

Commented:
Something like this?
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
	errEnable = objNetAdapter.EnableDHCP()
	If errEnable = 0 Then
		Wscript.Echo "DHCP has been enabled."
	Else
		Wscript.Echo "DHCP could not be enabled."
	End If
Next

Open in new window

There is also an EE thread dealing with this:
http://www.experts-exchange.com/Programming/Misc/Q_21368494.html
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Photographer
Awarded 2007
Top Expert 2008
Commented:
does it need to be VBSCRIPT - the netsh command will do this (I suppose you could always call this from VB is you need to)

netsh interface ip set address "Local Area Connection" dhcp

Author

Commented:
Woolmilkporc I am getting an error that DHCP could not be enabled.


I am trying to use this on Windows 2000 and Windows XP systems.

I noticed that the batch file does not work on Windows 2000 either.

Please advice.

KCTS
Could you please show me how to put the command in a script?

netsh interface ip set address "Local Area Connection" dhcp

Author

Commented:
kCTS

KCTS

netsh interface ip set address "Local Area Connection" dhcp solution did work. I was able to convert it to vbscript.

Thanks for the suggestion.
Vicki

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial