.BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Moderator: DosItHelp
.BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
So Say if I wanted to Block all .exe in Battle.net folder This bacth file would work:
for %%G in ("C:\Program Files (x86)\Battle.net*.exe") do (
netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=in action=block program="%%G" enable=yes profile=any netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=out action=block program="%%G" enable=yes profile=any
)
But say i would like to block in battle.net folder and all folders inside of battle.net folder how would I do this?
C:\Program Files (x86)\Battle.net**.exe
for %%G in ("C:\Program Files (x86)\Battle.net**.exe") do (
netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=in action=block program="%%G" enable=yes profile=any netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=out action=block program="%%G" enable=yes profile=any
)
^ This doesnt work BTW
Thanks for your help
for %%G in ("C:\Program Files (x86)\Battle.net*.exe") do (
netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=in action=block program="%%G" enable=yes profile=any netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=out action=block program="%%G" enable=yes profile=any
)
But say i would like to block in battle.net folder and all folders inside of battle.net folder how would I do this?
C:\Program Files (x86)\Battle.net**.exe
for %%G in ("C:\Program Files (x86)\Battle.net**.exe") do (
netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=in action=block program="%%G" enable=yes profile=any netsh advfirewall firewall add rule name="Blocked With Batchfile %%G" dir=out action=block program="%%G" enable=yes profile=any
)
^ This doesnt work BTW
Thanks for your help
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Try this:
Code: Select all
@Echo Off
SetLocal
Set "Fldr=%ProgramFiles(x86)%\Battle.net"
If Not Exist "%Fldr%\" Exit/B
If /I "%CD%" NEq "%Fldr%" PushD %Fldr%
Set "Cmnd=netsh advfirewall firewall add rule action=block"
For /R %%a In (*.exe) Do (For %%b In (in out) Do (
%Cmnd% name="blocked %%a via script" dir=%%b program="%%a"))
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
CarboN wrote:But say i would like to block in battle.net folder and all folders inside of battle.net folder how would I do this?
Did Compo's suggestion help you at all?
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Yes man sorry for being late. Beautiful I love you man!
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Compo wrote:Try this:Code: Select all
@Echo Off
SetLocal
Set "Fldr=%ProgramFiles(x86)%\Battle.net"
If Not Exist "%Fldr%\" Exit/B
If /I "%CD%" NEq "%Fldr%" PushD %Fldr%
Set "Cmnd=netsh advfirewall firewall add rule action=block"
For /R %%a In (*.exe) Do (For %%b In (in out) Do (
%Cmnd% name="blocked %%a via script" dir=%%b program="%%a"))
Yes man sorry for being late. Beautiful I love you man!
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Hey I just had a fresh install & I was using this however im having a error and advice?
http://imgur.com/a/sn1TX
http://imgur.com/a/sn1TX
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Code: Select all
If /I "%CD%" NEq "%Fldr%" PushD %Fldr%
Enclose the %Fldr% into quotation marks at the end of the line.
In order to be able to find out where the error occurred switch ECHO ON
Steffen
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
CarboN wrote:Hey I just had a fresh install & I was using this however im having a error and advice?
http://imgur.com/a/sn1TX
Two of my Internet cardinal sins.
1) Posting full desktop screenshots when Windows has the capability to capture a window.
2) Not copying from the console window and just pasting that info as text in the forums. Makes it a lot easier for everyone to see now and in the future for posterity.
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
@squasman, +1. know this is not SO, but totally agree with you.
Last edited by elzooilogico on 10 Sep 2016 04:36, edited 1 time in total.
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
aGerman wrote:Code: Select all
If /I "%CD%" NEq "%Fldr%" PushD %Fldr%
Enclose the %Fldr% into quotation marks at the end of the line.
In order to be able to find out where the error occurred switch ECHO ON
Steffen
Squashman wrote:CarboN wrote:Hey I just had a fresh install & I was using this however im having a error and advice?
http://imgur.com/a/sn1TX
Two of my Internet cardinal sins.
1) Posting full desktop screenshots when Windows has the capability to capture a window.
2) Not copying from the console window and just pasting that info as text in the forums. Makes it a lot easier for everyone to see now and in the future for posterity.
Thanks for your help here:
C:\Program Files (x86)\Battle.net>(For %b In (in out) Do (á áá ánetsh advfirewall firewall add rule action=block name="blocked C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe via script" dir=%b program="C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe" ) )
C:\Program Files (x86)\Battle.net>(á áá ánetsh advfirewall firewall add rule action=block name="blocked C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe via script" dir=in program="C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe" )
'á' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Battle.net>(á áá ánetsh advfirewall firewall add rule action=block name="blocked C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe via script" dir=out program="C:\Program Files (x86)\Battle.net\Battle.net.7963\Loader64.exe" )
'á' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Battle.net>pause
Press any key to continue . . .
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
Seems you have non-breaking spaces in your code that appear as 'á' in the console code pages 437 or 850. I recomment to write the code new from scratch or you edit it in a HEX Editor where you should see it as A0.
Steffen
Steffen
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
aGerman wrote:Seems you have non-breaking spaces in your code that appear as 'á' in the console code pages 437 or 850. I recomment to write the code new from scratch or you edit it in a HEX Editor where you should see it as A0.
Steffen
Hello! Thank you for your reply! I tried doing this however I just got something different:
' ' is not recognized as an internal or external command,
operable program or batch file.
Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders
This is a one off, I have uploaded the script, (inside a .rar archive), to an online server for download. It will only be there for maximum 48 hours.
You can get it here
If this functions untouched then we know it was your script corrupted.
You can get it here
If this functions untouched then we know it was your script corrupted.