/// <summary> /// Add a globally (open) port to firewall. /// </summary> public void AddGloballyPort(OpenPort openPort) { var type = Type.GetTypeFromProgID("HNetCfg.FWOpenPort"); var firewallOpenPort = Tools.Convert(() => (INetFwOpenPort)Activator.CreateInstance(type), openPort); _iNetFwMgr.LocalPolicy.CurrentProfile.GloballyOpenPorts.Add(firewallOpenPort); }
public static INetFwOpenPort Convert(Func <INetFwOpenPort> func, OpenPort item) { var result = func(); result.Enabled = item.Enabled; result.IpVersion = Convert(item.IpVersion); result.Name = item.Name; result.RemoteAddresses = item.RemoteAddresses; result.Scope = Convert(item.Scope); result.Port = item.Port; result.Protocol = Convert(item.ProtocolPort); return(result); }