Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Really, I tried everything, and there is no solution that works for me.

  1. WMI - everything perfect, but I can't change ip address when there is no connection. O_o Are you joking me? How can I make a connection without correct Ip-address?
  2. IPHelper - not doing anything. Just adding address to the table. Not work after reboot.
  3. netsh - the stupid way I think, but ok, if you don't no another ways you can try. Before you will know, that network adapters name can contain international characters. Did someone know how it works actually, I mean inside?
  4. Registry - working after reboot. I don't want to reboot. May be someone know how to notify about reg entries changes?
share|improve this question

migrated from stackoverflow.com Jan 28 '12 at 21:08

This question came from our site for professional and enthusiast programmers.

    
Changing the registry won't help because that does not let the rest of the system know of the update, at least not without rebooting. You need to modify it using the established APIs (which then change the registry for you). Have you tried disabling the network connection/adapter after making the change and then enabling it again? –  Synetech Jan 28 '12 at 21:32
    
perhaps this question from SO will be helpful –  Jeremy W Mar 11 '12 at 0:34
add comment

1 Answer

I made a script you may like.
It uses netsh to achieve what you need.

Just copy the code here into a new file and name it something like configip.bat or whatever you prefer (just don't call it ipconfig :)

You will need to modify several things in the script:
IP addresses you want, subnet masks and gateways.
All DNS servers are set to Google's (8.8.8.8) so they are very likely to work for you - unless your ISP requires you use their ones. In that case, use those.

You have several options for local network (wire and wireless), as well as DHCP (autoassigned IP).
There is also an option to dump your current configuration so you can see how it looks from netsh perspective.
This will allow you to modify my script with ease as you will have all the parameters in c:\networkconfig.txt file.

Of course, should you need further help with modification, I'll be here :)


@echo off
cls
:start
echo.
echo IP Configuration
echo.
echo 1. LAN Home
echo 2. LAN Office
echo 3. LAN DHCP
echo 4. WLAN Home
echo 5. WLAN Office
echo 6. Configuration Dump
echo 7. Quit
echo.

set /p userinput=Enter your choice: set option=%userinput:~0,1% if "%option%"=="1" goto homelan if "%option%"=="2" goto officelan if "%option%"=="3" goto landhcp if "%option%"=="4" goto homewan if "%option%"=="5" goto officewan if "%option%"=="6" goto configdump if "%option%"=="7" goto end echo. echo Invalid choice goto start

:homelan echo. echo Applying LAN HOME configuration. echo. netsh interface ip set address "Local Area connection" static 192.168.1.2 255.255.255.0 192.168.1.1 1 netsh interface ip set dns name="Local Area Connection" static 8.8.8.8 goto end

:officelan echo. echo Applying LAN OFFICE configuration. echo. netsh interface ip set address "Local Area connection" static 123.456.78.90 255.255.255.0 123.456.78.254 1 netsh interface ip set dns name="Local Area Connection" static 8.8.8.8 goto end

:landhcp echo. echo Applying DYNAMIC configuration. echo. netsh interface ip set address name="Local Area Connection" source=dhcp netsh interface ip set dns name="Local Area Connection" source=dhcp goto end

:homewan echo. echo Applying WLAN HOME configuration. echo. netsh interface ip set address name="Wireless Network Connection" source=dhcp netsh interface ip set dns name="Wireless Network Connection" source=dhcp goto end

:officewan echo. echo Applying WLAN OFFICE configuration. echo. netsh interface ip set address name="Wireless Network Connection" static 123.456.78.90 255.255.255.0 123.456.78.254 1 netsh interface ip set dns name="Wireless Network Connection" static 8.8.8.8 goto end

:configdump netsh -c interface dump > c:\networkconfig.txt echo. echo Config file "c:\networkconfig.txt" created. echo. echo To restore settings from config dump, use: echo netsh -f networkconfig.txt echo. pause goto end

:end

share|improve this answer
    
Is there a way to find out the names of the connections programmatically? Or at least the connection that is currently in use? –  Sterex Sep 4 '13 at 9:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.