Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Changing DNS With A .bat File

14 May 2014   #1

Windows 7 Professional x64
Changing DNS With A .bat File


I am doing exams soon so I need to start studying. I have set up OpenDNS to block some websites that may distract me but I don't need them blocked all the time. As OpenDNS offers no settings for time to block I need to change the DNS server back to my ISP's when the blocking is not needed. The command to change DNS in Command Prompt is

"C:\Netsh Interface ip set dns "Local Area Connection" static "[DNS GOES HERE]"

But with a START command in front of it this command does not work when put into a batch program.

Does anyone know either a better way of changing the DNS at different times or the correct way to insert this command into a batch file.


My System SpecsSystem Spec
14 May 2014   #2

Dual Boot: Windows 8.1 & Server 2012r2 VMs: Kali Linux, Backbox, Matriux, Windows 8.1

This may not be exactly what you want but you could always use your host file to redirect or simply block websites that may distract you.

Hosts File : Use in Windows 7 / Vista

Simply follow this tutorial. You don't have to use, which is your loopback address. You can use the IP address of say, a website you should be studying instead of your distractions

Simply erase the entries from the blocked files when you don't want them blocked.
My System SpecsSystem Spec
14 May 2014   #3

Win 7 Enterprise x64


You change it by modifying your Registry files. It works like a charm for me.
(Make it .bat and start it)
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "SearchList" /t REG_SZ /d "YOUR DNS"
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "NV Domain" /t REG_SZ /d "YOUR DNS"
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "Domain" /t REG_SZ /d "YOUR DNS"
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "DhcpDomain" /t REG_SZ /d "YOUR DNS"
This will clear it up the record from the registry.
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "SearchList" /t REG_SZ /d "" 
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "NV Domain" /t REG_SZ /d "" 
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "Domain" /t REG_SZ /d "" 
reg add "HKLM\System\CurrentControlSet\services\tcpip\Parameters" /f /v "DhcpDomain" /t REG_SZ /d ""
Good luck with you studying
My System SpecsSystem Spec

14 May 2014   #4

W7 Pro SP1 64bit

Quote   Quote: Originally Posted by JakeC112 View Post
But with a START command in front of it this command does not work when put into a batch program.
Don't use START.

Try this:
netsh interface ipv4 set dns name="Local Area Connection" static primary
netsh interface ipv4 add dns name="Local Area Connection"
ipconfig /flushdns
My System SpecsSystem Spec

 Changing DNS With A .bat File

Thread Tools

Similar help and support threads
Thread Forum
Changing .exe File Type Icons In File Explorer But Nowhere Else
Hello Everyone, I have kind of an odd question, I have been looking into changing file type icons when I came across an interesting conflict. I would like to be able to change the file type icon for all .exe files to the same file type icon within a file explorer. If you were to try to do...
Changing file name case
Does anyone have an easy way to change the case (upper to lower) for many files? Thanks for any assistance.
General Discussion
File Manager - file attribute display and changing
Hi In Windows 7 (and Vista) - all files displayed show only the file name. This is particularly noticeable with audio and image files - but I often have identical file names in different formats or sizes. Is there a way to make the .wav or .mp3 etc suffix visible and more importantly - can I...
General Discussion
changing file names
like changing the names on movies i download i remove the excess stuff like file type etc some of the files have a title aside from the file name and when i play them in the win media player they alternate between title and file name is there some way i can change the title
Music, Pictures & Video
Changing file options
There is a way to change all files to details, large icons or whatever and I forgot how. I have 10,000 pictures in 100+ folders so I open one and I got details then I open another I have extra large icons. I want to make them all the same.

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 05:27.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App