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
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 )
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With