Firewall: block all programs in a folder
Solved
Matt
-
Fenrisulfr01 Posted messages 17 Status Membre -
Fenrisulfr01 Posted messages 17 Status Membre -
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 réponses
Hello,
To do what you need, I suggest a small PowerShell block.
You must run PowerShell as an administrator.
Then type this:
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.
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? :
This code blocks all outgoing traffic from ALL applications in C:\Program Files\"DOSSIER"?
And if I want to disable this block?
Thanks again!
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 :)
This time should be the right one.
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
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 is
Then, I noticed an error on the second line: you need to add -recurse at the end. Which gives:
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:
If the folder in question is exactly named "DOSSIER" (with the quotes, the first command is
cd '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:
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
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
Ok, instead of the first and last apostrophe in the first line, put quotes. The problem comes from the apostrophe in "installation"
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?
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 command
However, the command
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!
I think the command
ls *.exe -recursedoesn't work.
However, the command
cd "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:
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
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
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
Thank you for your help!