This script helps you block internet access for specific programs using the Windows firewall automatically.
- The script blocks internet access for all
.exefiles in the script's directory and its subfolders. - It creates two firewall rules for each
.exefile found: one for incoming connections and one for outgoing connections.
- Download this repository.
- Extract the downloaded files.
- Copy the extracted
.batfile to the folder of the program(s) you want to block internet access for. - Run the script as an administrator (right-click on the script and choose "Run as administrator").
- Once the script finishes running, you can safely delete the
.batfile from the program folder. - Internet access for the specified programs will now be blocked.
- The script is written in
batchlanguage, a scripting language for the Windows command line. - It uses the
forandnetshcommands to add firewall rules for each.exefile in the current directory and its subdirectories. - The
for /Rcommand searches through all subdirectories, and%%frepresents the current file path. - Firewall rules are added using the
netsh advfirewall firewall add rulecommand. - Each rule blocks incoming and outgoing connections for a specific program.
- The rule's name, direction, and program path are specified in the command.
- The script includes the
setlocal enableextensionscommand to enable extensions andcd /d "%~dp0"to change to the script's directory. - A
pausecommand is included so you can review the results before closing the command prompt.
graph LR
subgraph Initialize
A[Set Echo Off]
B[Enable Local Extensions]
C[Change Directory]
end
subgraph Loop
D[Loop through files *.exe]
E[Add Outbound Firewall Rule]
F[Add Inbound Firewall Rule]
end
G[Display Pause Message]
A --> B --> C --> D --> E --> F --> D
D -->|Done| G
Note: Be cautious when using this script, as it blocks all internet access for the specified programs. Make sure to have backup copies of the files you want to block.
You can support me by buy me a coffee if u like to.