Firewall: block all programs in a folder
Solved
Matt
-
Fenrisulfr01 Posted messages 17 Status Member -
Fenrisulfr01 Posted messages 17 Status Member -
Hello,
I want to block internet access for all .exe programs in a folder from the Windows 7 firewall.
In fact, I want to block a list of X programs in the folder C:\Program Files\"FOLDER\"
I have no problem blocking the .exe files one by one, but it’s really very time-consuming!
Do you have a quick solution?
Thank you in advance!
I want to block internet access for all .exe programs in a folder from the Windows 7 firewall.
In fact, I want to block a list of X programs in the folder C:\Program Files\"FOLDER\"
I have no problem blocking the .exe files one by one, but it’s really very time-consuming!
Do you have a quick solution?
Thank you in advance!
16 answers
-
No, it does not accept having dir=in and dir=out.
However, you can redo everything by leaving only dir=in.-
I added a line and it works great
cd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
$appli = ls * -recurse | where {$_.name -like "*.exe"}
foreach ($app in $appli)
{
$name = $app.name
$path = $app.fullname
netsh adv firewall add rule name=$name dir=in action=block program=$path
netsh adv firewall add rule name=$name dir=out action=block program=$path
}
Thank you for your help!
-
-
Hello,
To do what you need, I suggest a small PowerShell block.
You must run PowerShell as an administrator.
Then type this:cd "your folder"
$appli = ls *.exe
foreach ($app in $appli)
{
$name = $app.name
netsh adv firewall add rule name=$name dir=out action=block program=$app.fullpath
}
Where your folder is the location of your applications that you want to block.
This will create a rule with the name of your application, which will block outgoing traffic.-
Hello,
Thank you very much for this response.
So basically, I just have to type this? :
cd C:\Program Files\"DOSSIER"
$appli = ls *.exe
foreach ($app in $appli)
{
$name = $app.name
netsh adv firewall add rule name=$name dir=out action=block program=$app.fullpath
}
This code blocks all outgoing traffic from ALL applications in C:\Program Files\"DOSSIER"?
And if I want to disable this block?
Thanks again!
-
-
Indeed, my mistake.
Let's change it once again :)
cd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
$appli = ls * -recurse | where {$_.name -like "*.exe"}
foreach ($app in $appli)
{
$name = $app.name
$path = $app.fullname
netsh adv firewall add rule name=$name dir=out action=block program=$path
}
This time should be the right one.-
Thank you, it seems to be working perfectly!
Is it possible to also add a restriction on incoming traffic?
Like this
cd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
$appli = ls * -recurse | where {$_.name -like "*.exe"}
foreach ($app in $appli)
{
$name = $app.name
$path = $app.fullname
netsh adv firewall add rule name=$name dir=in dir=out action=block program=$path
}
-
-
-
Hello,
If the folder in question is exactly named "DOSSIER" (with the quotes, the first command iscd 'C:\program Files\"DOSSIER"'
Then, I noticed an error on the second line: you need to add -recurse at the end. Which gives:$appli = ls *.exe -recurse
Yes, this code blocks the traffic of absolutely all .exe files in the folder C:\program Files\"DOSSIER".
To remove all previously created rules, use this code in the same manner:cd 'C:\program Files\"DOSSIER"'
$appli = ls *.exe
foreach ($app in $appli)
{
$name = $app.name
netsh adv firewall delete rule name=$name
}-
Hello,
Thank you for this response, but it’s not working.
I copied and pasted this code as is into Windows PowerShell (%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe) in admin mode:
cd 'C:\Program Files (x86)\Common Files\DOSSIER'
$appli = ls *.exe -recurse
foreach ($app in $appli)
{
$name = $app.name
netsh adv firewall add rule name=$name dir=out action=block program=$app.fullpath
}
How can I be sure that the command has been applied?
The software present in C:\Program Files (x86)\Common Files\DOSSIER is still connecting to the internet!
Thank you
-
-
Do you have any error messages?
If the command executed successfully, you can view the rules in "Windows Firewall with Advanced Security," under the "Outbound Rules" category. -
-
Press enter once or twice.
You should see "ok" or errors. -
Ok, instead of the first and last apostrophe in the first line, put quotes. The problem comes from the apostrophe in "installation"
-
That's what the -recurse is supposed to do following ls.
Can you runls *.exe* -recurse
and take a screenshot of the result? -
Just run
ls *.exe* -recurse
outside the block.
I want to make sure it finds anything. -
cd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
ls -recurse
And check if it outputs any .exe files. -
And if afterwards you do
ls *.exe -recurse
Does it output anything? -
Well, if he didn't find anything last time, it's because there are no executables in the subfolders.
Can you confirm that you have some by searching directly in Windows Explorer?-
Yes, I do have .exe files in different subfolders of C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager
I think the commandls *.exe -recurse
doesn't work.
However, the commandcd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
works fine.
ls -recurse
Here's a screenshot of part of the result from the above command where we can see that .exe files appear among others
http://img15.hostingpics.net/pics/934668Sanstitre.png
Thank you! -
-
-
ok, there are some weird things going on :)
Let's try something else.
In the solidworks folder:ls * -recurse | where {$_.name -like "*.exe"} -
That's already a good thing.
The block then becomes
cd "C:\Program Files (x86)\Common Files\SOLIDWORKS Installation Manager"
$appli = ls * -recurse | where {$_.name -like "*.exe"}
foreach ($app in $appli)
{
$name = $app.name
netsh adv firewall add rule name=$name dir=out action=block program=$app.fullpath
}-
Ok, it properly takes the command into account and successfully blocks the 7 .exe; I have 7 OKs (the rules have been added correctly to the firewall) but it doesn't work.
Indeed, the .exe files are still connecting to the net and the path seems incorrect to me. See screenshot:
http://img15.hostingpics.net/pics/874902Sanstitre.png
-