Batch files for changing network-adapter settings in windows 7
by Prabhat Rai

Posted on October 29, 2014 at 12:14 PM




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.




Share this

Search

  Recent Tips

See All »

  Recent Posts

  • Creating Installer for Laravel Project

    When you are working on a laravel project there is some basic setup that needs to be done for each install of the project. Like Permissions for ...

  • Laravel Queues With Supervisor

    In this blog, we are going to take a look into Laravel Queues. Queues allow you to defer the processing of a time-consuming task, such as sending a...

  • Partials & Utils in Handlebars

    PARTIALS Let’s say we have a structure like the following : data = { students : [{ name : ‘ABC’, roll : 1 }, { name : ‘DEF&...

See All »

  Recent Seminars

  • PHP 8 - Features

    PHP 8 has been officially released in November 2020! This new major update brings many optimizations and powerful features to the language. This...

  • ProxySQL

    ProxySQL is a high-performance SQL proxy. ProxySQL runs as a daemon watched by a monitoring process. The process monitors the daemon and restarts i...

  • Unix Commands & Shell Scripts to help save our time

    Time is important. We should not waste it doing trivial things. Automate things wherever possible.

See All »