I need to open specific port for my application.
I have tried using INetFwAuthorizedApplication
rule per application for all ports.
fwMgr.Lo
You could also just use PowerShell.
using System.Management.Automation;
...
private void OpenPort(int port)
{
var powershell = PowerShell.Create();
var psCommand = $"New-NetFirewallRule -DisplayName \"\" -Direction Inbound -LocalPort {port} -Protocol TCP -Action Allow";
powershell.Commands.AddScript(psCommand);
powershell.Invoke();
}