Batch files for changing network-adapter settings in windows 7

Every day I (and I guess most of us) face an issue regarding the adapter setting change. For office, we have a dedicated IP and settings, so change the settings, then as soon as I go home I need to connect to my home Wi-Fi and that need automatic IP and DNS settings, so again change the settings to default. Previously I was  on Ubuntu so I never cared about this as Ubuntu handles this very efficiently. But in Windows go to network settings then adapter settings blah blah blah. So here I will show to create 2 files that is office.bat and default.bat for doing it easily on windows 7. These files changes the settings as soon as you run these files.

 :: Configuration Variables ::
 set connectionName="Wireless Network Connection"
 set ipAddress=x.x.x.x
 set subnetMask=x.x.x.x
 set defaultGateway=x.x.x.x
 set primaryDNS=x.x.x.x
 set alternateDNS=x.x.x.x
 netsh interface ipv4 set address name=%connectionName% source=static addr=%ipAddress% mask=%subnetMask% gateway=%defaultGateway%
 netsh interface ipv4 set dns %connectionName% static %primaryDNS%
 netsh interface ipv4 add dns %connectionName% %alternateDNS% index=2

The content in these batch files is self explanatory

change the following

    connectionName -> The name of the connection you want to modify

Replace x.x.x.x of the variables with the following
    ipAddress-> your IP
    subnetMask-> subnet mask
    defaultGateway-> Default Gateway
    primaryDNS-> Preferred DNS server
    alternateDNS -> Alternate DNS server
save the file as office.bat, right click on the file and select “Run as Adminisrator” [If security warning comes up click OK] and your settings are changed to STPI.
For default the content of the batch file will be a little different
 :: Configuration Variable ::
 set connectionName="Wireless Network Connection"

 netsh interface ip set address %connectionName% dhcp
 netsh interface ip set dns %connectionName% dhcp
DHCP means Dynamic Host Configuration Protocol.
With DHCP, computers request IP addresses and networking parameters automatically from a DHCP server, reducing the need for a network administrator or a user to configure these settings manually. [From Wikipidea]

Save this file as default.bat and run as administrator and the setting change to DHCP.

These are applicable for LAN also you just need to give the correct connection name in the connectionName variable.

To enable/disable any adapter use
 :: Configuration Variable ::
 set connectionName="Wireless Network Connection"

 :: Disable ::
 netsh interface set interface %connectionName% DISABLED

 :: Enable ::
 netsh interface set interface %connectionName% ENABLED
Hope this helps you guys as it helped me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s