要点1:cmd命令行的输入命令
netsh wlan set hostednetwork mode=allow ssid=用户名 key=密码
netsh wlan start hostednetwork
netsh waln stop hostednetwork
netsh interface ip set address name="本地连接" source=dhcp
要点2:在C#中调用cmd.exe命令行
</div>
详细的代码如下:
namespace wifi01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//“创建wifi热点”按钮
private void button1_Click(object sender, EventArgs e)
{
string str;
string userName = textBox1.Text;
string password = textBox2.Text;
if (password.Length >= 8 && userName != null)
{
// 命令行输入命令,用来新建wifi
str="netsh wlan set hostednetwork mode=allow ssid="+userName+" key="+password;
create(str);
MessageBox.Show("新建了wifi热点",
"新建成功",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
label4.Text = "新建了wifi热点";
}
else
{
MessageBox.Show("你的账号为空或你的密码长度小于8",
"登陆失败",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
//"开启wifi"按钮
private void button2_Click(object sender, EventArgs e)
{
// 命令行输入命令,
string str = "netsh wlan start hostednetwork";
create(str);
label4.Text = "已启动wifi热点";
}
//“关闭wifi”按钮
private void button3_Click(object sender, EventArgs e)
{
// 命令行输入命令,
string str = "netsh wlan stop hostednetwork";
create(str);
label4.Text = "已关闭wifi热点";
}
&nb