public void OpenFirewallPorts() { Task.Factory.StartNew(() => { DeleteFirewallRule(FirewallWCFRule); string openWCFPort = String.Format("advfirewall firewall add Rule Name = \"{0}\" Dir = in action = allow protocol = TCP localport = {1}", FirewallWCFRule, this.WCFPort); var proc = new RedirectedProcess("netsh.exe", openWCFPort); return(proc.Start()); }).ContinueWith(ret => this.SetStatusMessage(String.Format("Opened firewall for port {0}. Netsh output: {1}", this.WCFPort, ret.Result.Item2.Trim())), this.UISheduler); Task.Factory.StartNew(() => { DeleteFirewallRule(FirewallSocketRule); string openSocketPort = String.Format("advfirewall firewall add Rule Name = \"{0}\" Dir = in action = allow protocol = TCP localport = {1}", FirewallSocketRule, this.PortNumber); var proc = new RedirectedProcess("netsh.exe", openSocketPort); return(proc.Start()); }).ContinueWith((ret => this.SetStatusMessage(String.Format("Opened firewall for port {0}. Netsh ouputput: {1}", this.PortNumber, ret.Result.Item2.Trim()))), this.UISheduler); }
Tuple <int, string> DeleteFirewallRule(string ruleName) { var proc = new RedirectedProcess("netsh.exe", String.Format("Advfirewall Firewall delete Rule Name=\"{0}\"", ruleName)); return(proc.Start()); }