我試圖從CMD中分離出結果,如果它是匹配的,它將插入到我的RichTextBox中
。這是我的代碼:
private void NetWorkCheker_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)。
{
var proc = new process
{
StartInfo = new ProcessStartInfo
{
檔案名 = "cmd.exe"。
Arguments = "/c ipconfig /all",
UseShellExecute = false,
RedirectStandardOutput = true。
CreateNoWindow = true, CreateNoWindow = true.
}
};
proc.Start()。
while (! proc.StandardOutput.EndOfStream)
{
Result.Text = "
" proc.StandardOutput.ReadLine()。
}
proc.WaitForExit()。
string SplitValue = Result.Text; // Here I want to split the result from my RichTextBox.
MessageBox.Show(SplitValue)。
}
我在這里被卡住了,所以我需要有人來修復我的代碼,如果可能的話。
uj5u.com熱心網友回復:
經過長時間的多次嘗試,我得到了答案
。這就是代碼:
private void linkLabel8_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)。
{
var proc = new process
{
StartInfo = new ProcessStartInfo
{
檔案名 = "cmd.exe"。
Arguments = "/c ipconfig /all",
UseShellExecute = false,
RedirectStandardOutput = true。
CreateNoWindow = true, CreateNoWindow = true.
}
};
string DHCP = ""/span>;
proc.Start()。
while (! proc.StandardOutput.EndOfStream)
{
if (Regex.IsMatch(proc.StandardOutput.ReadLine(), "Lease Expires . . . . . . . : ")) //找到匹配下的結果,如果匹配Lease Expires。
{
DHCP = "
" proc.StandardOutput.ReadToEnd(); //設定值為var。
}
}
proc.WaitForExit()。
Result.Text = "
" DHCP.Split(new string[] {"NetBIOS"/span>}, StringSplitOptions. RemoveEmptyEntries)[0];//將CMD的結果分割到richtextbox。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326919.html
標籤:
