private void AddWindowsFirewallEntry() { if (Environment.OSVersion.Version.Major < 6) { //below vista try { if (!WindowsFirewall.PortExists(Protocol.TCP, _service.ExternalSelfEP.Port)) { WindowsFirewall.AddPort("Bit Chat - TCP", Protocol.TCP, _service.ExternalSelfEP.Port, true); } if (!WindowsFirewall.PortExists(Protocol.UDP, 41733)) { WindowsFirewall.AddPort("Bit Chat - Local Discovery", Protocol.UDP, 41733, true); } } catch { } } else { //vista & above try { string appPath = Assembly.GetEntryAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\"); if (!WindowsFirewall.RuleExistsVista("Bit Chat", appPath)) { WindowsFirewall.AddRuleVista("Bit Chat", "Allow incoming connection request to Bit Chat application.", FirewallAction.Allow, appPath, Protocol.ANY); } } catch { } } }