Block All .exe and .dll Files in a Directory Using Windows Firewall
Block All .exe and .dll Files in a Directory Using Windows Firewall
When managing security or testing applications in a restricted environment, you might need to prevent all executable and dynamic link library (DLL) files within a specific folder (and its subfolders) from accessing the network. This can be crucial for sandboxing software or preventing unauthorized communication.
Instead of manually adding rules for every single file, you can use a simple batch script to automate the process.
How it Works
The provided batch script automates the creation of Windows Firewall rules using the netsh command. It scans the current directory and all its subdirectories for any .exe and .dll files and creates both Inbound and Outbound block rules for each one.
Key Features:
- Recursive Scanning: It finds all relevant files within the folder structure.
- Automatic Naming: It uses the current folder's name as a prefix for the firewall rules, making it easy to identify and manage them later.
- Inbound & Outbound Blocking: It ensures that no network traffic can enter (Inbound) or leave (Outbound) via these specific files.
- Admin Check: The script automatically verifies if it is being run with Administrator privileges.
Instructions
- Place the Script: Save the
BlockAllFilesInDirWithFirewallRule.batfile in the folder you wish to restrict. - Run as Administrator: Right-click the
.batfile and select Run as administrator. This is mandatory because modifying the Windows Firewall requires elevated permissions. - Review and Confirm: The script will display the folder path and the name it will use for the rules. Review this information and follow the on-screen prompts to proceed.
Warning: Be extremely careful when running this script. Once the rules are applied, all applications within that directory will be unable to access the internet or your local network.
Summary Table
| Feature | Detail |
|---|---|
| File Types | .exe, .dll |
| Rule Direction | Inbound and Outbound |
| Action | Block |
| Scope | Current folder and all subfolders |
| Requirement | Administrator Privileges |