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 classThrown if a modification cannot be performed because the calling process does not have administrative rights.static classThrown if an error other than missing access rights is encountered.static enumThe network protocol for a Windows firewall rule.static enumThe Windows firewall profiles.static classA Windows firewall rule.static enumThe direction of a Windows firewall rule. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddRule(WinFirewall.Rule rule) Add a new firewall rule.static intdeleteRules(WinFirewall.Rule template) Delete firewall rules based on the given rule as a template.static intdeleteRulesByExecutable(String executablePath) Delete all firewall rules for a specific executable path.static intdeleteRulesByGroup(String groupName) Delete all firewall rules with a specific group name.static intdeleteRulesByName(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:
trueif the rule was created,falseif 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.
-