Link to home
Start Free TrialLog in
Avatar of hypercube
hypercubeFlag for United States of America

asked on

WIN 7 .bat file to change IP address .. DHCP problem

I have a few batch files that I use to switch NIC settings.  These are all "Run as Administrator".

For static IP, I use this:
@ECHO OFF
set varip=192.168.0.99
set varsm=255.255.255.0
set vargw=192.168.0.1
set vargwmetric=1
set vardns1=192.168.0.1
set vardns2=8.8.8.8
set vardnsindex1=1
set vardnsindex2=2

REM ***** You don’t need to change anything below this line! ******
ECHO Setting IP, mask, gateway and DNS
REM netsh set address "Local Area Connection" static %varip% %varsm% %vargw% %vargwmetric%
netsh interface ip set address "Local Area Connection" static %varip% %varsm% %vargw% %vargwmetric%
ECHO Setting Primary DNS
netsh interface ip set dns name="Local Area Connection" source=static address=none
ECHO Setting primary DNS
netsh interface ip add dns  name="Local Area Connection" %vardns1% index=%vardnsindex1%
ECHO Setting secondary DNS
netsh interface ip add dnsserver "Local Area Connection" %vardns2% index=%vardnsindex2%
ECHO Here are the new settings for %computername%:
netsh int ip show config
pause
end

Open in new window


To switch to DHCP "get an address automatically", I use this:
@ECHO OFF
REM ***** You don’t need to change anything below this line! ******
netsh interface ip set address name="Local Area Connection" dhcp
netsh interface ip set dns name="Local Area Connection" dhcp
netsh interface ip set default gateway name="Local Area Connection" dhcp
netsh interface ip show config[embed=file 906425]
pause
end

Open in new window

The problem is, that when I switch from a static address to a DHCP configuration, the default gateway IP address remains and the DHCP button isn't turned on - and the NIC settings dialog appears to disagree with the results of ipconfig that says DHCP YES!

User generated image
At the same time, the NIC ipv4 settings look like this:
User generated image
What might be the problem here?
ASKER CERTIFIED SOLUTION
Avatar of Zephyr ICT
Zephyr ICT
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hypercube

ASKER

I tried those things but nothing in the results has changed.

ipconfig result and the GUI result are different re: DHCP.
This is Windows 7 right? I tested on W7 64bit machine and it works just fine? Any error message you see in Windows event log maybe?
reboot...  :-(
Everything works now.
Thanks all!
Thanks again!