示例#1
0
        /// <summary>
        /// Execute a WPR command with specified command line args. Used e.g. to start/stop/cancel tracing.
        /// Commands can take a long time to execute. Currently the WCF service has a time of 10 minutes.
        /// </summary>
        /// <param name="wpaArgs">WPR command line args</param>
        /// <returns>stdout and stderr of executed command when it has finished.</returns>
        public Tuple <int, string> ExecuteWPRCommand(string wpaArgs)
        {
            RedirectedProcess proc = null;

            wpaArgs = Environment.ExpandEnvironmentVariables(wpaArgs);
            if (wpaArgs.StartsWith(ViewModel.CustomCommandPrefix))
            {
                proc = new RedirectedProcess("cmd.exe", $"/C {wpaArgs.Substring(ViewModel.CustomCommandPrefix.Length)}");
            }
            else
            {
                proc = new RedirectedProcess("wpr.exe", wpaArgs);
            }
            var lret = proc.Start(ThisExeStartDirectory);

            return(lret);
        }
示例#2
0
        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);
        }
示例#3
0
        Tuple <int, string> DeleteFirewallRule(string ruleName)
        {
            var proc = new RedirectedProcess("netsh.exe", String.Format("Advfirewall Firewall delete Rule Name=\"{0}\"", ruleName));

            return(proc.Start());
        }