简单Wifi共享工具,增加了网络承载检测。
贴上主程序源码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; namespace WindowsFormsApplication1 { public partial class mainFrom : Form { public mainFrom() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { bool flag = Cmdinfo(); if (!flag) { MessageBox.Show("不好意思,您的网卡不支持网络承载,不能启动虚拟网络", "抱抱提示你", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// <summary> /// 执行并返回cmd命令值 /// </summary> /// <param name="strinfo"></param> /// <returns></returns> private static bool Cmdinfo() { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; bool pingrst; p.Start(); p.StandardInput.WriteLine("netsh wlan show drivers"); p.StandardInput.WriteLine("exit"); string strRst = p.StandardOutput.ReadToEnd(); if (strRst.IndexOf("支持的承载网络 : 是") != -1) pingrst = true; else if (strRst.IndexOf("支持的承载网络 : 否") != -1) pingrst = false; else pingrst = false; p.Close(); return pingrst; } private void b_start_Click(object sender, EventArgs e) { Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); process.StandardInput.WriteLine("netsh wlan start hostednetwork"); process.StandardInput.WriteLine("exit"); process.WaitForExit(); process.Close(); MessageBox.Show("乐宝宝,Wifi已经开启咯!o(∩_∩)o", "抱抱提示你", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void b_close_Click(object sender, EventArgs e) { Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); process.StandardInput.WriteLine("netsh wlan stop hostednetwor"); process.StandardInput.WriteLine("exit"); process.WaitForExit(); process.Close(); MessageBox.Show("乐宝宝,Wifi关闭咯,欢迎下次使用!", "抱抱提示你", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void button1_Click(object sender, EventArgs e) { string name = tb_user.Text; string pwd = tb_pwd.Text; if (Encoding.Default.GetByteCount(name) > 0 && Encoding.Default.GetByteCount(pwd) >= 8) { Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); process.StandardInput.WriteLine("netsh wlan set hostednetwork mode=allow ssid=" + name + " key=" + pwd);//执行的命令 process.StandardInput.WriteLine("exit"); process.WaitForExit(); process.Close(); MessageBox.Show("乐宝宝,密码已经修改咯!账号:" + name + "密码:" + pwd + "要牢记!", "抱抱提示你", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("乐宝宝,出错咯,是不是密码没有8位数啊?!", "抱抱提示你", MessageBoxButtons.OK, MessageBoxIcon.Information); } //清空 tb_pwd.Text = ""; } private void mainFrom_FormClosed(object sender, FormClosedEventArgs e) { Application.Exit(); } } }