This command will work in both Windows XP and Windows Vista

Why Should I Bother?

This can be useful for a few reasons:
  • You use DHCP at home and a Static IP at work (assuming you transport your laptop)
  • You need to set the IP address for multiple computers
  • You are in a hotel
  • etc
Basically, if you transport your laptop into different environments that require different network settings.

How To

I’ll first post the code, then I’ll explain what’s going on.
The code:
  1. @ECHO OFF
  2. set varip=65.88.48.77
  3. set varsm=255.255.255.224
  4. set vargw=65.88.48.65
  5. set vardns1=66.78.202.254
  6. set vardns2=66.78.210.254
  7. set varhome=www.google.com
  8. REM ***** You don’t need to change anything below this line! ******
  9. ECHO This fanciness is brought to you by Saman Sadeghi!
  10. ECHO Setting IP Address and Subnet Mask
  11. netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%
  12. ECHO Setting Gateway
  13. netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1
  14. ECHO Setting Primary DNS
  15. netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%
  16. ECHO Setting Secondary DNS
  17. netsh int ip add dns name = "Local Area Connection" addr = %vardns2%
  18. ECHO Setting Internet Explorer Homepage to %varhome%
  19. reg add "hkcusoftwaremicrosoftinternet explorermain" /v "Start Page" /d "%varhome%" /f
  20. ECHO Here are the new settings for %computername%:
  21. netsh int ip show config
  22. pause
 
Now, I realize that it looks like there is a lot going on there but there really isn’t. The way I have written the code, the user will not see all of the coding when the batch file is run, but they will see feedback as to what is going on. Also, you don’t really have to declare all of the variables first, you could just pass them directly from that line. Example:
  1. netsh int ip set address name = "Local Area Connection" source = static addr = 65.88.48.77 mask = 255.255.255.224
But, I created this so that you (or whoever you give this to) wont have to go searching through the code if the variables need to be changed – plus, it’s better programing practice to declare your variables first!

How To I Use This Code?

Open a new text file and copy/paste the code, then save the file as a .bat. You will need to change all of the variables (the six at the top of the code) to meet your networking needs!

Download

You can download the raw code – again, you must save the file with a .bat extension.

What’s Going On?

It really is pretty self explanatory, all of the netsh int commands set the corresponding network connection information. The second-to-last command (the one for setting the home page) sets a registry key with the value that you declared earlier (%varhome%). It may not be necessary for your application, but I thought I should include it for you anyway!

How To Reset To DHCP

I have written another article and posted the code to Reset Your IP Address Via Batch File