How To: Create A Batch File For Changing Network Settings In Windows Vista

Let’s suppose you are using two network settings with your Windows Vista computer frequently. Either it’s a wireless network or wired network, all the same: Every time you want to change the IP, subnet mask, default gateway and DNS Server(s) of your network connection in any flavor of Windows, you have to click through menus, submenus, and from that you go to yet another submenu.

There is an easier and better way to switch your Windows Vista computer between these network settings : the command “netsh” on your command prompt can change all the aforementioned settings, and if you put them in a batch file, you can change them with a double mouse click.To familiarize yourself with the “netsh” command, click on “Start/Run” and enter “cmd”. The command prompt opens. If you type netsh /? in the command line, you’ll see it all of its great features. It does have one drawback: to change network settings of a NIC (Network Interface Controller), you need to know its name in Windows. This defaults to “Local Area Connection”, or “LAN Verbinding” in Dutch. This name (which is a unique identifier for a NIC on Windows) will determine which NIC you’ll change.

Batch File For Changing Network Settings In Windows Vista

netsh interface ip set address name=”Local Area Connection” source=static addr=111.222.333.444 mask=255.255.255.255
netsh interface ip set address name=”Local Area Connection” gateway=555.666.777.888 gwmetric=0
netsh interface ip set dns name=”Local Area Connection” source=static addr=999.111.222.333
netsh interface ip add dns name = “Local Area Connection” addr = 444.555.666.777

(Note: Of course you must enter the numbers if the IP, subnet mask, gateway and DNS Server(s) according to your settings. As most of you know, 111.222.333.444 is just an example of an actually non-existing IP address).

( Note: Assuming that your second network connection settings are different, say with DHCP, than create another batch file and name it differently from the first.

netsh interface ip set address name=”Local Area Connection” dhcp
netsh interface ip set dns name=”Local Area Connection” dhcp

Save the file as”Connection_settings_2.bat”.Your batch file is now ready for execution, now double click the batch file that you just created and you will find your network settings configured in a few seconds.

If you need WINS you should enter the code

netsh interface ip set wins name=”Local Area Connection” source=static addr=   .   .   .

at the end of the batch files(s) with the correct settings instead of the dots.)

Now its the time to test your new batch files. When you double-click on one, a command prompt window opens and the batch file is processed line by line. This takes some time, it is not done instantly. When the processes are finished the window closes.

To check if the settings are applied correctly, open an elevated command prompt in Windows Vista and enter “ipconfig”. Then double-click on the second batch file and after it is finished put the command prompt where you entered “ipconfig” in focus and enter “ipconfig” again. The settings have changed with one double-click

Another Method:

@ECHO OFF

set varip=11.22.33.44
set varsm=255.255.255.224
set vargw=55.66.77.88
set vardns1=66.78.202.254
set vardns2=66.78.210.254

ECHO Setting IP to static
netsh int ipv4 set address name = “Wireless Network Connection” source = static address = %varip% mask = %varsm%

ECHO Setting IP Address and Subnet Mask
netsh int ipv4 set address name = “Wireless Network Connection” address = %varip% mask = %varsm% gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
netsh int ip set dns name = “Wireless Network Connection” source = static addr = %vardns1%

ECHO Setting Secondary DNS
netsh int ip add dns name = “Wireless Network Connection” addr = %vardns2%

ECHO Here are the new settings for %computername%:
netsh int ip show config

pause

(Note: You must change the numbers of the IP, subnet mask, gateway and DNS Server(s) according to your settings.)

Note: All the processes explained above needs elevation.So dont forget to use an elevated command prompt in Windows Vista.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Popularity: 13%

Did You Like This Post? Then You Might Find These Also Interesting:

Written by Tony on February 8th, 2009 with no comments.
Read more articles on Vista Networking.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .