我正在做一个项目,在这个项目中,我使用netsh获取所有wlan网络,然后获取密钥。起初,我有3个应用程序和2个.txt文件,在这些应用程序之间传递信息。现在,我成功地将所有3个应用程序复制到1中,同时仍然使用这些文本文件。现在,我想要摆脱这些文件有一个独立的执行。
对于实际问题:在代码的一部分中,我打开了一个netsh.exe窗口,并使用流线器将一些命令写入其中。之后,我使用streamreader读取所有内容,并将其打印为txt文件之一。之后,我读取文件的内容,同时跳过几行,并将其余的行打印到列表框中。有没有一种不使用文本文件来完成所有这些的方法?
以下是一些代码:
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
var p = new Process();
var startinfo = new ProcessStartInfo("cmd.exe")
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false
};
p.StartInfo = startinfo;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("@echo off");
sw.WriteLine("netsh wlan show profiles");
}
}
using (StreamReader sr = p.StandardOutput)
{
if (sr.BaseStream.CanRead)
{
}
}
}产出如下:
Profile auf Schnittstelle WLAN:
Gruppenrichtlinienprofile (schreibgeschützt)
---------------------------------
<Kein>
Benutzerprofile
---------------
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something
Profil für alle Benutzer : something发布于 2022-06-28 06:28:48
使用MemoryStream而不是FileStream
https://stackoverflow.com/questions/72781259
复制相似问题