-1
我有一个netsh分析器,我想获取每个找到的循环的详细信息。如何使用列表<string>在cmd中循环进程?
private void wifiButton_Click(object sender, EventArgs e)
{
Process cmd = new Process();
cmd.StartInfo.FileName = "netsh.exe";
System.Threading.Thread.Sleep(50);
cmd.StartInfo.Arguments = "wlan show profiles";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();
//* Read the output (or the error)
string output = cmd.StandardOutput.ReadToEnd();
textBox3.Text = output;
cmd.WaitForExit();
// output would be set by earlier code
var Output = textBox3.Text;
var regex = new Regex(@"All User Profile[\s]+: (.*)");
var resultList = new List<string>();
foreach (Match match in regex.Matches(Output))
{
resultList.Add(match.Groups[1].ToString());
}
textBox4.Text = string.Join(", ", resultList);
上面的代码工作,下面我想要通过CMD再次运行结果列表并获得详细结果。
for (int i = 0; i < resultList.Count; i++)
{
Process cmd2 = new Process();
cmd.StartInfo.FileName = "netsh.exe";
System.Threading.Thread.Sleep(50);
cmd.StartInfo.Arguments = "wlan show profiles name=" resultList(0) + " key=clear";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();
//* Read the output (or the error)
string output2 = cmd2.StandardOutput.ReadToEnd();
textBox5.Text = output2;
cmd.WaitForExit();
}
}
不应该是'resultList [i]'?你遇到了什么错误?什么阻止你的代码工作? – David
你的问题是什么? – code
@大卫我可以吻你哈哈,你是完全正确的人。这和我错误标记我的第二套循环为cmd而不是cmd2。看起来它大部分工作。 –