我想创建一个 C# 应用程序来创建 WLAN 网络。我目前使用命令提示符使用 netsh。我的应用程序应该通过单击按钮来执行此操作。这是我在管理模式下的命令提示符中使用的命令“netsh wlan set Hostednetwork mode=allow ssid=sha key=12345678”,然后输入“netsh wlan startHostednetwork”。当我这样做时,我可以创建一个 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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)