set dns script RRS feed

  • Question

  • Hi, 

    i´m trying to change dns server settings on my windows client with startup script.

    and i want to change only wired connection settings so script first change all and then wifi is changed back to dhcp. 

    script works in my windows 10 client but not working in windows 7. why? what i need not change to get this working in both versions. thx


    rem  echo off
    set dnsserver=myDNS
    set dnsserver2=myDNS
    for /f "tokens=1,2,3*" %%i in ('netsh interface show interface') do (
     if %%i EQU Enabled (
     echo change "%%l" : %dnsserver%
     netsh interface ipv4 set dnsserver name="%%l" static %dnsserver% both
     netsh interface ipv4 add dnsserver name="%%l" %dnsserver2% index=2
    netsh interface ipv4 set dnsservers "Wi-Fi" dhcp

    ipconfig /flushdns


    • Edited by Sheriffi Monday, September 3, 2018 9:13 AM
    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:34 PM This is not "debug/fix/rewrite my script for me" forum
    Monday, September 3, 2018 8:28 AM

All replies

  • hello

    make sure "wi-fi" connection name on your windows 7 is the same in your code.

    try dhcp ip-address after "dhcp"

    Thursday, September 6, 2018 6:41 AM
  • that´s not the problem.  problem is in start of the script. script is not setting static dns servers. 

    when i run manually that command, works just fine. But when i run that whole script.. nothing change..and like i said, works fine in w10

    Friday, September 7, 2018 1:06 PM