Package com.install4j.api.windows
Class WinFirewall
java.lang.Object
com.install4j.api.windows.WinFirewall
Collection of static methods to add and delete Windows firewall rules.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown if a modification cannot be performed because the calling process does not have administrative rights.static class
Thrown if an error other than missing access rights is encountered.static enum
The network protocol for a Windows firewall rule.static enum
The Windows firewall profiles.static class
A Windows firewall rule.static enum
The direction of a Windows firewall rule. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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> Retrieve the currently active firewall profiles.
-
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.FirewallExceptionRetrieve 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.
-