我尝试为wifi热点制作一些简单的GUI但是在点击按钮后,它没有写入textBox1并且窗口转到冻结。我还没试过button_off。
我会很高兴任何提示。谢谢。
这是我的代码:
namespace Wifi_hotspot
{
public partial class Form1 : Form
{
private String name, password;
public Form1()
{
InitializeComponent();
}
private void button_on_Click(object sender, EventArgs e)
{
ProcessStartInfo zapnout = new ProcessStartInfo("cmd");
zapnout.FileName = "cmd.exe";
zapnout.UseShellExecute = false;
zapnout.RedirectStandardOutput = true;
zapnout.CreateNoWindow = true;
zapnout.RedirectStandardInput = true;
var info = Process.Start(zapnout);
info.StandardInput.WriteLine("netsh wlan set hostednetwork mode=allow ssid=" + name + " key=" + password);
info.StandardInput.WriteLine("netsh wlan start hostednetwork");
string s = info.StandardOutput.ReadToEnd();
info.Close();
textBox1.Text = s;
}
private void button_off_Click(object sender, EventArgs e)
{
ProcessStartInfo vypnout = new ProcessStartInfo();
vypnout.UseShellExecute = false;
vypnout.RedirectStandardOutput = true;
vypnout.CreateNoWindow = true;
vypnout.RedirectStandardInput = true;
var info = Process.Start(vypnout);
info.StandardInput.WriteLine("netsh wlan stop hostednetwork");
string s = info.StandardOutput.ReadToEnd();
textBox1.Text = s;
}
private void textBox_ssid_TextChanged(object sender, EventArgs e)
{
if (textBox_ssid.TextLength > 0 && textBox_heslo.TextLength > 0)
{
enableBtn(true);
name = textBox_ssid.Text;
password = textBox_heslo.Text;
}
else
{
enableBtn(false);
}
}
private void enableBtn(bool enable)
{
button_on.Enabled = enable;
button_off.Enabled = enable;
}
}
}