Batch Scripts

Block Distracting Websites

Focus mode for the whole PC: block the sites that eat your time in every browser, then unblock them with one click when you're done.

 

Windows only. Read the code before running any script you download. Your browser or Windows SmartScreen may warn about .bat files; choose "Keep" / "More info › Run anyway" if you trust it.

Keeps this tool on this device so it works without internet, even after a refresh.

Had fun, or did this help? I’d appreciate any donation :) Not needed, but money buys temporary happiness at least lol

What it does

Browser extensions that block sites only work in one browser and are easy to switch off in the moment. Windows has a simpler trick built in: the hosts file, which can point a website's name nowhere, so it won't load in any browser or app on the PC.

This script adds the sites you list to the hosts file (with and without www), marked so it can find them again, and clears the DNS cache so the block starts straight away. Run it in unblock mode to remove exactly those lines and nothing else. It needs administrator rights.

How to use Block Distracting Websites

  1. List the sites to block, one per line (just the name, like youtube.com).
  2. Download and run the script as administrator. Restart your browser.
  3. To unblock, make the script again in unblock mode and run that as administrator.

Making the .bat file yourself

The download button already gives you a ready-to-run .bat file. If you'd rather copy the code, or the download gets blocked, you can make the file yourself in Notepad:

  1. Click Copy code, open Notepad and paste.
  2. Choose File › Save as. Set Save as type to All files (*.*). This step matters: if it stays on "Text documents", Notepad quietly adds .txt.
  3. Type a name ending in .bat, like my-script.bat, and save. You can also type the name in quotes, "my-script.bat", which forces that exact name even on "Text documents".
  4. Check the file's icon: a .bat file shows a gear-window icon, not a notepad page. Double-click it to run.
My file ended up as script.bat.txt and opens in Notepad. How do I fix it?

Windows hides file extensions by default, so the file looks like script.bat but is really script.bat.txt. Turn extensions on: in File Explorer, choose View › Show › File name extensions (Windows 11) or tick File name extensions on the View tab (Windows 10). Then rename the file, delete the .txt at the end, and click Yes when Windows asks if you're sure you want to change the extension.

How it works

CommandWhat it does
%SystemRoot%\System32\drivers\etc\hostsWindows checks this file before looking up any website name.
0.0.0.0 youtube.comSends the name to an address that goes nowhere, so the site can't load.
# LSB focusA marker on every line this script adds, so unblocking removes only those lines.
findstr /v /c:"# LSB focus"Copies the hosts file without the marked lines, which clears old blocks before adding new ones.
hosts.lsb-backupA copy of the hosts file from before each run, next to the original.
ipconfig /flushdnsForgets cached lookups so the block works right away.

Block Distracting Websites FAQ

A site still opens.

Close and reopen the browser. If it still loads, the browser may be using "secure DNS" (DNS over HTTPS), which some browsers use in a way that skips the hosts file; turn that off in the browser's privacy settings while you want the block.

Does it block apps too?

Yes, anything on this PC that looks up that name, including desktop apps. It doesn't affect your phone or other devices.

My antivirus warned about the hosts file.

Some security tools watch the hosts file because malware edits it too. The change here is yours and only blocks the sites you listed; you can see every line in the file.

How do I run a .bat file?

Double-click it. To see or edit the code, right-click it and choose Edit (or open it in Notepad). Scripts that need administrator rights say so; for those, right-click › Run as administrator.

Is this script uploaded or tracked?

No. The code is built in your browser from the settings above and downloaded straight to your PC.

Related