WinFirewall (install4j API)
Description: declaration: package: com.install4j.api.windows, class: WinFirewall

# Class WinFirewall

java.lang.Object
com.install4j.api.windows.WinFirewall

public class WinFirewall extends Object
Collection of static methods to add and delete Windows firewall rules.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `WinFirewall.AccessDeniedException`
  Thrown if a modification cannot be performed because the calling process does not have administrative rights.
  `static class`
  `WinFirewall.FirewallException`
  Thrown if an error other than missing access rights is encountered.
  `static enum`
  `WinFirewall.NetworkProtocol`
  The network protocol for a Windows firewall rule.
  `static enum`
  `WinFirewall.ProfileType`
  The Windows firewall profiles.
  `static class`
  `WinFirewall.Rule`
  A Windows firewall rule.
  `static enum`
  `WinFirewall.RuleDirection`
  The direction of a Windows firewall rule.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `addRule(WinFirewall.Rule rule)`
  Add a new firewall rule.
  `static int`
  `deleteRules(WinFirewall.Rule template)`
  Delete firewall rules based on the given rule as a template.
  `static int`
  `deleteRulesByExecutable(String executablePath)`
  Delete all firewall rules for a specific executable path.
  `static int`
  `deleteRulesByGroup(String groupName)`
  Delete all firewall rules with a specific group name.
  `static int`
  `deleteRulesByName(String ruleName)`
  Delete all firewall rules with a specific name.
  `static Set<WinFirewall.ProfileType>`
  `getCurrentProfileTypes()`
  Retrieve the currently active firewall profiles.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### addRule

    public static boolean addRule(WinFirewall.Rule rule) throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Add a new firewall rule.

    This method can only be called with full administrative rights.

    Parameters:
      `rule` - the rule
    Returns:
      `true` if the rule was created, `false` if the rule already exists.
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.

  - ### deleteRulesByExecutable

    public static int deleteRulesByExecutable(String executablePath) throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Delete all firewall rules for a specific executable path.

    This method can only be called with full administrative rights.

    Parameters:
      `executablePath` - the executable path
    Returns:
      the number of deleted rules.
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.

  - ### deleteRulesByName

    public static int deleteRulesByName(String ruleName) throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Delete all firewall rules with a specific name.

    This method can only be called with full administrative rights.

    Parameters:
      `ruleName` - the rule name
    Returns:
      the number of deleted rules.
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.

  - ### deleteRulesByGroup

    public static int deleteRulesByGroup(String groupName) throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Delete all firewall rules with a specific group name.

    This method can only be called with full administrative rights.

    Parameters:
      `groupName` - the group name
    Returns:
      the number of deleted rules.
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.

  - ### deleteRules

    public static int deleteRules(WinFirewall.Rule template) throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Delete firewall rules based on the given rule as a template. Properties that are not explicitly set for this template match any value.

    This method can only be called with full administrative rights.

    Parameters:
      `template` - the template rule
    Returns:
      the number of deleted rules.
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.

  - ### getCurrentProfileTypes

    public static Set<WinFirewall.ProfileType> getCurrentProfileTypes() throws WinFirewall.AccessDeniedException, WinFirewall.FirewallException
    Retrieve the currently active firewall profiles.
    Returns:
      a set of profiles
    Throws:
      `WinFirewall.AccessDeniedException` - thrown when the action could not be performed due to missing rights.
      `WinFirewall.FirewallException` - thrown when another type of error was encountered.