要點(diǎn)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
要點(diǎn)2:在C#中調(diào)用cmd.exe命令行
詳細(xì)的代碼如下:
namespace wifi01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//“創(chuàng)建wifi熱點(diǎn)”按鈕
private void button1_Click(object sender, EventArgs e)
{
string str;
string userName = textBox1.Text;
string password = textBox2.Text;
if (password.Length >= 8 && userName != null)
{
// 命令行輸入命令,用來(lái)新建wifi
str="netsh wlan set hostednetwork mode=allow ssid="+userName+" key="+password;
create(str);
MessageBox.Show("新建了wifi熱點(diǎn)",
"新建成功",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
label4.Text = "新建了wifi熱點(diǎn)";
}
else
{
MessageBox.Show("你的賬號(hào)為空或你的密碼長(zhǎng)度小于8",
"登陸失敗",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
//"開(kāi)啟wifi"按鈕
private void button2_Click(object sender, EventArgs e)
{
// 命令行輸入命令,
string str = "netsh wlan start hostednetwork";
create(str);
label4.Text = "已啟動(dòng)wifi熱點(diǎn)";
}
//“關(guān)閉wifi”按鈕
private void button3_Click(object sender, EventArgs e)
{
// 命令行輸入命令,
string str = "netsh wlan stop hostednetwork";
create(str);
label4.Text = "已關(guān)閉wifi熱點(diǎn)";
}
//在cmd控制臺(tái)輸入命令,
private void create(string str)
{
//process用于調(diào)用外部程序
System.Diagnostics.Process p = new System.Diagnostics.Process();
//調(diào)用cmd.exe
p.StartInfo.FileName = "cmd.exe";
//是否指定操作系統(tǒng)外殼進(jìn)程啟動(dòng)程序
p.StartInfo.UseShellExecute = false;
//可能接受來(lái)自調(diào)用程序的輸入信息
//重定向標(biāo)準(zhǔn)輸入
p.StartInfo.RedirectStandardInput = true;
//重定向標(biāo)準(zhǔn)輸出
p.StartInfo.RedirectStandardOutput = true;
//重定向錯(cuò)誤輸出
p.StartInfo.RedirectStandardError = true;
//不顯示程序窗口
p.StartInfo.CreateNoWindow = true;
//啟動(dòng)程序
p.Start();
//睡眠1s。
System.Threading.Thread.Sleep(1000);
//輸入命令
p.StandardInput.WriteLine(str);
//一定要關(guān)閉。
p.StandardInput.WriteLine("exit");
}
//自動(dòng)IP連接 按鈕
private void button4_Click(object sender, EventArgs e)
{
// 命令行輸入命令,用來(lái)自動(dòng)連接wifi:netsh interface ip set address name="本地連接" source=dhcp
string str="netsh interface ip set address name=/"本地連接/" source=dhcp";
string str1 = "銳捷是否提示你設(shè)置自動(dòng)獲取IP/n"+"或你想自動(dòng)獲取IP,請(qǐng)按確定";
DialogResult result = MessageBox.Show(str1,"自動(dòng)連接IP",
MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
create(str);
label4.Text = "銳捷自動(dòng)獲取IP";
}
}
}
}
新聞熱點(diǎn)
疑難解答
圖片精選