我想创建一个C#应用程序来创建WLAN网络。我目前使用命令提示符使用netsh。我的应用程序应该在按钮单击时执行此操这是我在命令提示符中使用的命令管理模式“netsh wlan set hostednetwork mode = allow ssid = sha key = 12345678”之后我输入“netsh wlan start hostednetwork”。当我这样做时,我可以创建一个wifi局域网。在C#中我编码如下
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "wlan set hostednetwork mode=allow ssid=sha key=12345678"+"netsh wlan start hostednetwork";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
}
答案 0 :(得分:3)
你不应该这样做:+"netsh wlan start hostednetwork"
到第一个进程的参数。这意味着你在控制台输入了这个:
netsh wlan set hostednetwork mode=allow ssid=sha key=12345678netsh wlan start hostednetwork
相反,为第二行创建一个新流程:
private void button1_Click(object sender, EventArgs e)
{
Process p1 = new Process();
p1.StartInfo.FileName = "netsh.exe";
p1.StartInfo.Arguments = "wlan set hostednetwork mode=allow ssid=sha key=12345678";
p1.StartInfo.UseShellExecute = false;
p1.StartInfo.RedirectStandardOutput = true;
p1.Start();
Process p2 = new Process();
p2.StartInfo.FileName = "netsh.exe";
p2.StartInfo.Arguments = "wlan start hostednetwork";
p2.StartInfo.UseShellExecute = false;
p2.StartInfo.RedirectStandardOutput = true;
p2.Start();
}