Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modify Windows Firewall with command prompt

using Command Prompt to modify Windows Firewall

can i allow Domain/Public/Private checkmarks all in the same row (like i can do by manually clicking)?

what i have so far makes 3 entries, one checkmark for each type:

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\MyApp.exe" enable=yes profile=domain

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\MyApp.exe" enable=yes profile=public

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\MyApp.exe" enable=yes profile=private

like image 701
Dito Avatar asked May 26 '26 13:05

Dito


2 Answers

Here's what you can do to solve it:

profile=Private and/or public and/or domain
(To add rule in more than one profile use “,” E.g.: profile=private, domain )
like image 131
Becosses Avatar answered May 31 '26 13:05

Becosses


Try this:

@echo off
setlocal

set "fcmd=netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\MyApp.exe" enable=yes profile="
for %a in (domain public private) do (
    echo %fcmd%%a

If you want to run it in batch file, just double the %'s for %a to %%a. Remove the Echo when you test for acceptable output.

And just to tidy things up a bit:

@echo off
setlocal

set fcmd=netsh advfirewall firewall add rule ^
 name="MyApp" dir=in action=allow program="C:\MyApp.exe" ^
 enable=yes profile=
for %a in (domain public private) do (
    echo %fcmd%%a
)
like image 26
Matt Williamson Avatar answered May 31 '26 13:05

Matt Williamson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!