Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a batch file that I use on my WinXP SP3 (I found it on the net and it worked).

SWiTCH TO CONNECTION 1

@ECHO OFF set varip=192.168.0.118 set varsm=255.255.255.0 set vargw=192.168.0.1 set vardns1=121.1.3.81 set vardns2=121.1.3.16

ECHO Setting IP Address and Subnet Mask netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%

ECHO Setting Gateway netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS netsh int ip add dns name = "Local Area Connection" addr = %vardns2%

SWITCH TO CONNECTION 2

@ECHO OFF set varip=192.168.0.118 set varsm=255.255.255.0 set vargw=192.168.0.2 set vardns1=192.168.0.2 set vardns2=192.168.0.8

ECHO Setting IP Address and Subnet Mask netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%

ECHO Setting Gateway netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS netsh int ip add dns name = "Local Area Connection" addr = %vardns2%

Unfortunately this batch file does not work on my Win7 (ultimate) machine. I am wondering what to edit to make it work. I've searched some sites and tried a thing or two but I was not able to find a solution. Thank you very much in advance for the help.

share|improve this question
    
Are there any specific errors being generated? –  ponsfonze Dec 20 '12 at 14:34
    
Every time I use the said script, no errors were generated, but the ip, gateway and dns (1st and 2nd) remains the same. I've tried changing the ip to ipv4 but it does not work either (ip remains the same) –  user181841 Dec 21 '12 at 7:29

1 Answer 1

Your batch script seems a lot different to what was suggested on other websites, like THIS or THIS, so I rewrote your batch script.

I also turned your two batch scripts into one, that, after execution, will ask you which connection you want to switch to.

@echo off

::: Note ::::
echo Please make sure you are starting this batch script as an Administrator.

:::: Choice ::::
set /P c=Do you want to switch to connection one, or two [1/2]? 
if /I "%c%" EQU "1" goto :ConnectionOne
if /I "%c%" EQU "2" goto :ConnectionTwo
goto :Exit

:::: Variables ::::

:ConnectionOne
set varip=192.168.0.118 
set varsm=255.255.255.0
set vargw=192.168.0.1 
set vardns1=121.1.3.81
set vardns2=121.1.3.16
goto :Start

:ConnectionTwo
set varip=192.168.0.118 
set varsm=255.255.255.0
set vargw=192.168.0.2
set vardns1=192.168.0.2
set vardns2=192.168.0.8
goto:Start

:::: Program ::::

:Start
echo.
echo Setting IP Address [%varip%]
echo Setting Subnet Mask [%varsm%
echo Setting Gateway [%vargw%]
netsh interface ip set address name="Local Area Connection" static %varip% %varsm% %vargw%

echo Setting Primary DNS [%vardns1%]
echo Setting Secondary DNS [%vardns2%]
netsh interface ip set dns name="Local Area Connection" static %vardns1%
netsh interface ip add dns name="Local Area Connection" %vardns2% index=2

:Exit
pause
exit

Please note, even though the above batch script was written and tested on Windows 8.1, it should still work the same on Windows 7. If it doesn't, please let me know.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.