9

I'm trying to delete a Windows Firewall rule from command line using netsh. I'm trying with the below syntax; however, it is not working for me result wise.

netsh advfirewall firewall delete rule program="C\Program Files (x86)\utorrent\uTorrent.exe"

What is the correct syntax for this? I am using Windows 7 Ultimate 64-bit.

Riccardo La Marca
  • 263
  • 1
  • 5
  • 18

3 Answers3

14

Don't use the "Program" parameter and value, use "Rule" name in the delete statement.

You can run netsh advfirewall firewall show rule status=enabled name=all or perhaps netsh advfirewall firewall show rule status=enabled name=all | FIND /I "uTorrent" to get a list of the rules that are enabled to help location the actual name of the rule.

Once this is determined, you can run netsh advfirewall firewall delete rule name="<Rule Name>" and plug the name of the rule in accordingly for it to remove that rule.

Examples

Create a rule with the name "IP Block"

netsh advfirewall firewall add rule name="IP Block" dir=in interface=any action=block remoteip=<IPaddress>/32

Delete a rule with the name "IP Block"

netsh advfirewall firewall delete rule name="IP Block"

Further Resources

4

None of your attempts contains a correct rule name.

If not supplying a distinct rule name use (according to this help ) name=all in combination with program="C:\Program Files (x86)\utorrent\uTorrent.exe"

netsh advfirewall firewall delete rule name=all program="C:\Program Files (x86)\utorrent\uTorrent.exe"

name = { all | RuleName }
Required.  You can specify one of the following values:

  • The rule name of the connection security rule you want deleted.
  • all.  Specifies that all rules matching the criteria in the other parameters are deleted.  If no other parameters are included in the command then all connection security rules are deleted.
LotPings
  • 7,391
2

I have found another powerfull solution:

@echo off
setlocal EnableExtensions DisableDelayedExpansion
REG EXPORT "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" "%TEMP%\RegBackup.reg" /y > NUL 2> NUL
TYPE "%TEMP%\RegBackup.reg" | FINDSTR /i /v torrent > "%TEMP%\RegBackupNew.reg"
REG DELETE "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /f /va > NUL 2> NUL
REG IMPORT "%TEMP%\RegBackupNew.reg" 2> NUL
REG EXPORT "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" "%TEMP%\RegBackup.reg" /y > NUL 2> NUL
TYPE "%TEMP%\RegBackup.reg" | FINDSTR /i /v torrent > "%TEMP%\RegBackupNew.reg"
REG DELETE "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /f /va > NUL 2> NUL
REG IMPORT "%TEMP%\RegBackupNew.reg" 2> NUL
DEL /q "%TEMP%\RegBackup.reg" 2> NUL
DEL /q "%TEMP%\RegBackupNew.reg" 2> NUL
endlocal
Riccardo La Marca
  • 263
  • 1
  • 5
  • 18