我想创建一个C#应用程序来创建无线局域网。我目前使用命令提示符使用netsh。我的应用程序应该按一下按钮就可以做到这一点。下面是我在命令提示符下使用的命令"netsh set hostednetwork mode=allow ssid=sha key=12345678“之后,我输入了"netsh start hostednetwork”。当我这样做,我可以创建一个无线局域网。在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();
}发布于 2013-08-23 10:28:50
您不应该这样做:对第一个进程的参数进行+"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();
}https://stackoverflow.com/questions/18400364
复制相似问题