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
JakeC112

Windows 7 Professional x64
 
 
Changing DNS With A .bat File

Hi,

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.

Thanks
Jake


My System SpecsSystem Spec
.
14 May 2014   #2
Gator

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 127.0.0.1, 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
FrancisF

Win 7 Enterprise x64
 
 

Hi,

You change it by modifying your Registry files. It works like a charm for me.
(Make it .bat and start it)
Code:
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.
Code:
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
F.
My System SpecsSystem Spec
.

14 May 2014   #4
UsernameIssues

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:
Code:
netsh interface ipv4 set dns name="Local Area Connection" static 8.8.8.8 primary
netsh interface ipv4 add dns name="Local Area Connection" 8.8.4.4
ipconfig /flushdns
pause
My System SpecsSystem Spec
Reply

 Changing DNS With A .bat File




Thread Tools Search this Thread
Search this Thread:

Advanced Search




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...
Customization
changing file owner
I'm getting a few problems that seem related to the fact some of my files and folders are owned by the administrator or require administrator permissions. I use GFI Backup. It reports problems with lacking permissions to access certain files -- unless I turn off UAC. Also there are many...
General Discussion
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 the swap file
Hi all, I would like to move the swap file from the hard drive its currently residing in to a 4 gb USB stick id like to install. How would I do this and what would be the best size to make the swap file. Also, is there any mileage in my doing this in Win7? It used to be a handy speed...
Performance & Maintenance


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 13:57.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App