我想创建一个C#应用程序来创建WLAN网络。我当前使用命令提示符使用netsh。我的应用程序应该在单击按钮时执行此操作。这是我在管理模式下的命令提示符中使用的命令"netsh wlan set hostednetwork mode=allow ssid=sha key=1234678",然后我输入"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();
}
您不应该这样做:对第一个进程的参数+"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();
}