Closed Agagamand closed 5 years ago
Win Vista+:
var rule = FirewallWAS.Instance.Rules
.FirstOrDefault(r => r.ApplicationName == myAppname);
if (rule != null) {
FirewallWAS.Instance.Rules.Remove(rule);
}
Win XP:
var rule = FirewallLegacy.Instance.Rules
.OfType<FirewallLegacyApplicationRule>()
.FirstOrDefault(r => r.ExecutableAddress == myAppname);
if (rule != null) {
FirewallLegacy.Instance.Rules.Remove(rule);
}
This is for current v2 alpha. Doing the same with 1.6 is also quite similar to this; just the name of some of the classes should be replaced.
FirewallWAS in 1.6 its FirewallManager, but I can not find analog ApplicationName in version 1.6.
FirewallWAS
in 1.6 is FirewallAPIv2.Firewall
var rule = WindowsFirewallHelper.FirewallAPIv2.Firewall.Instance.Rules
.OfType<WindowsFirewallHelper.FirewallAPIv2.Rules.StandardRule>()
.FirstOrDefault(r => r.ApplicationName == myAppname);
if (rule != null) {
WindowsFirewallHelper.FirewallAPIv2.Firewall.Instance.Rules.Remove(rule);
}
VisualStudeo writes an error ".OfType": «method which is not valid in the given context error»
You have not updated NuGet package WindowsFirewallHelper v2 alpha for a long time
For OfType()
you need to import System.Linq
. I suggest using tools like ReSharper. These tools will help you when you are missing an import or other similar things. This speeds up your development.
I also forgot to write the ()
after OfType
so the error message might be due to that as well. Comments edited to fix that.
These things happen when you try to write a piece of code from memory and not using an IDE. xD
I only know path to.exe, I do not know the name of Firewoll rule. How can I find a rule (to remove it) knowing only the path to the file?