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
- Open your network connections folder in the Control Panel.
- Windows usually calls the Network Interface Card “Local Area Connection” If you want to change the settings of your wireless network settings go to the appropriate status window. Make sure you know the name.
- Click on it, than click “Properties” and there double-click “Internet Protocol (TCP/IP)” This is where you usually go when you change those settings.
- Now open your notepad editor and open a new file and enter the following code:
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=9220.127.116.113
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).
- Save the file as “Connection_settings_1.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.
- Create another batch file using the similar procedure, in this batch file you enter the IP’s that are relevant to your other location.
- Now you should be having two batch files one for your office network and the other for your home network.
( 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
- Open your notepad editor and open a new file and enter the following code:
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
(Note: You must change the numbers of the IP, subnet mask, gateway and DNS Server(s) according to your settings.)
- Save the file as “Connection_settings.bat” and then run.
Note: All the processes explained above needs elevation.So dont forget to use an elevated command prompt in Windows Vista.