# WinFirewall

Import: `import com.install4j.api.windows.WinFirewall;`

```java
public class WinFirewall
```

Collection of static methods to add and delete Windows firewall rules.

| Type | Kind | Description |
|---|---|---|
## Nested types

| [WinFirewall.AccessDeniedException](WinFirewall.AccessDeniedException.md) | class | Thrown if a modification cannot be performed because the calling process does not have administrative rights. |
| [WinFirewall.FirewallException](WinFirewall.FirewallException.md) | class | Thrown if an error other than missing access rights is encountered. |
| [WinFirewall.NetworkProtocol](WinFirewall.NetworkProtocol.md) | enum | The network protocol for a Windows firewall rule. |
| [WinFirewall.ProfileType](WinFirewall.ProfileType.md) | enum | The Windows firewall profiles. |
| [WinFirewall.Rule](WinFirewall.Rule.md) | class | A Windows firewall rule. |
| [WinFirewall.RuleDirection](WinFirewall.RuleDirection.md) | enum | The direction of a Windows firewall rule. |

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`addRule(Rule)`](#addrule-rule) | `boolean` | Add a new firewall rule. |
| [`deleteRulesByExecutable(String)`](#deleterulesbyexecutable-string) | `int` | Delete all firewall rules for a specific executable path. |
| [`deleteRulesByName(String)`](#deleterulesbyname-string) | `int` | Delete all firewall rules with a specific name. |
| [`deleteRulesByGroup(String)`](#deleterulesbygroup-string) | `int` | Delete all firewall rules with a specific group name. |
| [`deleteRules(Rule)`](#deleterules-rule) | `int` | Delete firewall rules based on the given rule as a template. |
| [`getCurrentProfileTypes()`](#getcurrentprofiletypes) | `Set<ProfileType>` | Retrieve the currently active firewall profiles. |

### addRule(Rule)

```java
public static boolean addRule(Rule rule) throws AccessDeniedException, 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:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

### deleteRulesByExecutable(String)

```java
public static int deleteRulesByExecutable(String executablePath) throws AccessDeniedException, 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:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

### deleteRulesByName(String)

```java
public static int deleteRulesByName(String ruleName) throws AccessDeniedException, 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:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

### deleteRulesByGroup(String)

```java
public static int deleteRulesByGroup(String groupName) throws AccessDeniedException, 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:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

### deleteRules(Rule)

```java
public static int deleteRules(Rule template) throws AccessDeniedException, 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:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

### getCurrentProfileTypes()

```java
public static Set<ProfileType> getCurrentProfileTypes() throws AccessDeniedException, FirewallException
```

Retrieve the currently active firewall profiles.


**Returns:** a set of profiles

**Throws:**

- `AccessDeniedException` — thrown when the action could not be performed due to missing rights.
- `FirewallException` — thrown when another type of error was encountered.

