.BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

.BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#1 Post by CarboN » 12 Jun 2016 08:51

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

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#2 Post by Compo » 12 Jun 2016 15:28

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"))

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#3 Post by foxidrive » 14 Jun 2016 23:15

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?

CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#4 Post by CarboN » 17 Jun 2016 09:35

Yes man sorry for being late. Beautiful I love you man!

CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#5 Post by CarboN » 17 Jun 2016 09:35

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!

CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#6 Post by CarboN » 09 Sep 2016 14:08

Hey I just had a fresh install & I was using this however im having a error and advice?

http://imgur.com/a/sn1TX

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#7 Post by aGerman » 09 Sep 2016 15:06

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
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#8 Post by Squashman » 09 Sep 2016 21:13

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.

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#9 Post by elzooilogico » 10 Sep 2016 04:29

@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.

CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#10 Post by CarboN » 12 Sep 2016 11:42

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 . . .

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#11 Post by aGerman » 12 Sep 2016 12:07

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

CarboN
Posts: 6
Joined: 12 Jun 2016 08:48

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#12 Post by CarboN » 16 Sep 2016 12:06

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.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: .BAT Windows Firewall Blocking All .EXE In a Folder and All Subfolders

#13 Post by Compo » 16 Sep 2016 13:14

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.

Post Reply