Netsh advfirewall firewall delete rule name= rule name program="C:\MyApp\MyApp.exe" Netsh firewall delete allowedprogram C:\MyApp\MyApp.exe Netsh advfirewall firewall add rule name= "Open Port 80" dir=in action=allow protocol=TCP localport=80Ĭommand example 3: Delete enabled programs or ports Old command Netsh firewall add portopening TCP 80 "Open Port 80"
Run the following commands: netsh advfirewall firewall add rule name="My Application" dir=in action=allow program= "C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=privateįor more information about how to add firewall rules, run the following command: netsh advfirewall firewall add rule ?Ĭommand example 2: Enable a port Old command Netsh firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=ALL Netsh advfirewall firewall add rule name="My Application" dir=in action=allow program= "C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain Netsh firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=Domain Netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes Netsh firewall add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLE Command example 1: Enable a program Old command You can use these examples to help you migrate from the older netsh firewall context to the new netsh advfirewall firewall context.Īdditionally, the netsh advfirewall commands that you can use to obtain detailed inline help are provided. Some examples of frequently used commands are provided in the following tables. To start a command prompt with elevated permissions, find the icon or Start menu entry that you use to start a command prompt session, right-click it, and then click Run as administrator. If you are a member of the Administrators group, and User Account Control is enabled on your computer, run the commands from a command prompt with elevated permissions.