Netsh命令在RichTectBox中未正确返回 [英] Netsh command doesnt return correct in RichTectBox

查看:72
本文介绍了Netsh命令在RichTectBox中未正确返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.我是编程新手,这是我的代码

Hi there. I m new in programming here is my code

class TcpIpCommands
    {
        public string Check()
        {
            Process p = new Process();
            p.StartInfo.FileName = @"C:\Windows\syswow64\netsh.exe";
            p.StartInfo.Arguments = "int tcp show global";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(737);
            p.Start();
            p.WaitForExit();
            return p.StandardOutput.ReadToEnd();
        }

        public string Command(string FileName, string Arguments)
        {
            ProcessStartInfo p = new ProcessStartInfo();
            p.FileName = FileName;
            p.Arguments = Arguments;
            p.UseShellExecute = false;
            p.CreateNoWindow = true;
            p.RedirectStandardOutput = true;
            p.StandardOutputEncoding = Encoding.GetEncoding(737);

            using (Process process = Process.Start(p))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = reader.ReadToEnd();
                    return result;
                }
            }            
        }

        public string Reseting()
        {
            Process p = new Process();
            p.StartInfo.FileName = @"C:\Windows\syswow64\netsh.exe";
            p.StartInfo.Arguments = @"interface tcp reset";
            p.StartInfo.Verb = "runas";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(737);
            p.Start();
            p.WaitForExit();
            return p.StandardOutput.ReadToEnd();
        }
    }

这是按钮上的代码

private void BtnCheck_Click(object sender, EventArgs e)
        {
            TcpIpCommands tic = new TcpIpCommands();
            richTextBox1.Text = tic.Check();
        }    
        private void btnChimney_Click(object sender, EventArgs e)
        {
            TcpIpCommands tic = new TcpIpCommands();
            richTextBox1.Text = tic.Command(@"C:\Windows\system32\netsh.exe", "interface tcp set global chimney=enabled");            
        }    
        private void BtnReset_Click(object sender, EventArgs e)
        {
            TcpIpCommands tic = new TcpIpCommands();
            richTextBox1.Text = tic.Reseting();
        }

现在是什么问题.如果我点击了显示按钮,则所有显示的内容都会在文本框中正确显示.如果我从其他按钮中碰到任何东西,我都会在文本框中收到消息在ipv4上设置全局命令失败,参数不正确",但参数已更改 在ipv4上,而不是在ipv6上.

What is the problem now. If i hit the show button is all displayed correct on textbox. If i hit anything from other buttons i get in text box the message "set global command failed on ipv4 the parameter is incorrect", BUT the parameters have change on ipv4 and not on ipv6.

示例我点击了启用烟囱的烟囱按钮.我在TextBox中收到了以上消息,并在ipv4中启用了disable,而在ipv6中禁用了.

Example i hit chimney button that enables the chimney. I get in TextBox the above message and in ipv4 from disable is enabled now and on ipv6 is disabled.

注意:我已经在Windows 7 x64,Windows 10 x64上进行了测试

Note: I have tested on Windows 7 x64, Windows 10 x64

我在清单中添加了特权提升.

I have add elevated priviliges with manifest adding.

推荐答案

这确实与编程无关,但是与netsh的使用有关,因为错误来自该命令.请将您的问题发布到TechNet.
This really has nothing to do with programming but rather an issue with your usage of netsh since the errors are coming from that command. Please post your question to TechNet.


这篇关于Netsh命令在RichTectBox中未正确返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆