wifi共享小工具
MainForm.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace MyWifi
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public string executeCmd(string Command)
{
Process process = new Process
{
StartInfo = { FileName = " cmd.exe ", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true }
};
process.Start();
process.StandardInput.WriteLine(Command);
process.StandardInput.WriteLine("exit");
process.WaitForExit();
string str = process.StandardOutput.ReadToEnd();
process.Close();
return str;
}
private void btnCreate_Click(object sender, EventArgs e)
{
if ((textName.Text == "") || (textPsw.Text == ""))
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "用户名和密码均不能为空!");
}
else if (textPsw.Text.Length < 8)
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "密码不能少于8位!");
}
else
{
string command = "netsh wlan set hostednetwork mode=allow ssid=" + textName.Text + " key=" + textPsw.Text;
string str2 = executeCmd(command);
if (((str2.IndexOf("承载网络模式已设置为允许") > -1) && (str2.IndexOf("已成功更改承载网络的 SSID。") > -1)) && (str2.IndexOf("已成功更改托管网络的用户密钥密码。") > -1))
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "新建共享网络成功!");
}
else
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "搭建失败,请重试!");
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
string command = "netsh wlan set hostednetwork mode=disallow";
if (executeCmd(command).IndexOf("承载网络模式已设置为禁止") > -1)
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "禁止共享网络成功!");
}
else
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "操作失败,请重试!");
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (executeCmd("netsh wlan start hostednetwork").IndexOf("已启动承载网络") > -1)
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "已启动承载网络!");
}
else
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "承载失败,请尝试新建网络共享!");
}
}
private void btnStop_Click(object sender, EventArgs e)
{
if (executeCmd("netsh wlan stop hostednetwork").IndexOf("已停止承载网络") > -1)
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "已停止承载网络!");
}
else
{
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss") + "---" + "停止承载失败!");
}
}
private void MainForm_Load(object sender, EventArgs e)
{
init();
ListBoxLogs.AddCtrlValue(this, sysLogs, DateTime.Now.ToString("HH:mm:ss")+"---"+"欢迎使用本系统");
}
#region MyRegion
WebBrowser W = new WebBrowser();
WebBrowser WW = new WebBrowser();
WebBrowser WWW = new WebBrowser();
WebBrowser WWWW = new WebBrowser();
private void init()
{
Timer t = new Timer();
t.Enabled = true;
t.Interval = 5000;
}
private void t_Tick(object sender, EventArgs e)
{
this.W.Refresh();
this.WW.Refresh();
}
#endregion
private void textName_TextChanged(object sender, EventArgs e)
{
}
}
}
ListBoxLogs.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace MyWifi
{
public class ListBoxLogs
{
private delegate void AddCtrlValueHandler(Control ctrl, string value);
private delegate void ChangeComboBoxValueHandler(ComboBox ctrl);
private delegate void SetCtrlEnableHandler(Control ctrl, bool value);
private delegate void SetCtrlValueHandler(Control ctrl, string value);
public static void AddCtrlValue(Form parentForm, Control ctrl, string value)
{
if (parentForm.InvokeRequired)
{
AddCtrlValueHandler method = new AddCtrlValueHandler(AddCtrlValueMethod);
parentForm.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
AddCtrlValueMethod(ctrl, value);
}
}
private static void AddCtrlValueMethod(Control ctrl, string value)
{
if (ctrl is TextBox)
{
TextBox box = ctrl as TextBox;
box.Text = box.Text + value;
}
else if (ctrl is Label)
{
Label label = ctrl as Label;
label.Text = label.Text + value;
}
else if (ctrl is ListBox)
{
ListBox listbox = ctrl as ListBox;
if (listbox.Items.Count > 200)
{
listbox.Items.Clear();
}
listbox.Items.Add(value);
if (listbox.Items.Count > 1)
{
listbox.SelectedIndex = (listbox.Items.Count - 1);
}
}
else if (ctrl is RichTextBox)
{
RichTextBox richtextbox = ctrl as RichTextBox;
richtextbox.Text += value + "\r\n";
if (richtextbox.Text.Length > 6000)
{
richtextbox.Text = string.Empty;
}
}
}
public static void ChangeComboBoxValue(Form parentForm, ComboBox ctrl)
{
if (parentForm.InvokeRequired)
{
ChangeComboBoxValueHandler method = new ChangeComboBoxValueHandler(ChangeComboBoxValueMethod);
parentForm.BeginInvoke(method, new object[] { ctrl });
}
else
{
ChangeComboBoxValueMethod(ctrl);
}
}
private static void ChangeComboBoxValueMethod(ComboBox ctrl)
{
if (ctrl.Items.Count > 1)
{
if (ctrl.SelectedIndex == 0)
{
ctrl.SelectedIndex = 1;
}
else
{
ctrl.SelectedIndex = 0;
}
}
}
public static void SetCtrlEnable(Form parentForm, Control ctrl, bool value)
{
if (parentForm.InvokeRequired)
{
SetCtrlEnableHandler method = new SetCtrlEnableHandler(SetCtrlEnableMethod);
parentForm.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlEnableMethod(ctrl, value);
}
}
public static void SetCtrlEnable(UserControl parentCtrl, Control ctrl, bool value)
{
if (parentCtrl.InvokeRequired)
{
SetCtrlEnableHandler method = new SetCtrlEnableHandler(SetCtrlEnableMethod);
parentCtrl.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlEnableMethod(ctrl, value);
}
}
private static void SetCtrlEnableMethod(Control ctrl, bool value)
{
//if (ctrl is TextBox)
//{
// TextBox box = ctrl as TextBox;
// box.Enabled = value;
//}
//if (ctrl is ComboBox)
//{
// ComboBox box2 = ctrl as ComboBox;
// box2.Enabled = value;
//}
//if (ctrl is Label)
//{
// Label label = ctrl as Label;
// label.Enabled = value;
//}
//if (ctrl is Button)
//{
// Button button = ctrl as Button;
// button.Enabled = value;
//}
//if (ctrl is NumericUpDown)
//{
// NumericUpDown down = ctrl as NumericUpDown;
// down.Enabled = value;
//}
//if (ctrl is Form)
//{
// Form form = ctrl as Form;
// form.Enabled = value;
//}
////if (ctrl is IPTextBox)
////{
//// IPTextBox box3 = ctrl as IPTextBox;
//// box3.Enabled = value;
////}
//if (ctrl is GroupBox)
//{
// GroupBox box4 = ctrl as GroupBox;
// box4.Enabled = value;
//}
//if (ctrl is CheckBox)
//{
// CheckBox box5 = ctrl as CheckBox;
// box5.Enabled = value;
//}
try
{
ctrl.Enabled = value;
}
catch { }
}
public static void SetCtrlValue(Form parentForm, Control ctrl, string value)
{
if (parentForm.InvokeRequired)
{
SetCtrlValueHandler method = new SetCtrlValueHandler(SetCtrlValueMethod);
parentForm.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlValueMethod(ctrl, value);
}
}
public static void SetCtrlValue(UserControl parentCtrl, Control ctrl, string value)
{
if (parentCtrl.InvokeRequired)
{
SetCtrlValueHandler method = new SetCtrlValueHandler(SetCtrlValueMethod);
parentCtrl.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlValueMethod(ctrl, value);
}
}
private static void SetCtrlValueMethod(Control ctrl, string value)
{
if (ctrl is TextBox)
{
TextBox box = ctrl as TextBox;
box.Text = value;
}
else if (ctrl is ComboBox)
{
ComboBox box2 = ctrl as ComboBox;
try
{
int selIndex = 0;
try
{
selIndex = int.Parse(value);
if (selIndex < box2.Items.Count - 1)
{
box2.SelectedIndex = selIndex;
}
else
{
box2.SelectedIndex = box2.FindString(value);
}
}
catch
{
box2.SelectedIndex = box2.FindString(value);
}
}
catch (Exception exception)
{
//LogFile.Log.Debug(exception.Message);
}
}
else if (ctrl is Label)
{
Label label = ctrl as Label;
label.Text = value;
}
else if (ctrl is Button)
{
Button button = ctrl as Button;
button.Text = value;
}
else if (ctrl is NumericUpDown)
{
NumericUpDown down = ctrl as NumericUpDown;
down.Value = int.Parse(value);
}
else if (ctrl is Form)
{
Form form = ctrl as Form;
form.Text = value;
}
else if (ctrl is ProgressBar)
{
ProgressBar bar = ctrl as ProgressBar;
bar.Value = int.Parse(value);
}
else if (ctrl is CheckBox)
{
try
{
CheckBox cb = ctrl as CheckBox;
cb.Checked = bool.Parse(value);
}
catch
{
}
}
else
{
ctrl.Text = value;
}
}
private delegate void SetCtrlVisibleHandler(Control ctrl, bool value);
public static void SetCtrlVisible(Form parentForm, Control ctrl, bool value)
{
if (parentForm.InvokeRequired)
{
SetCtrlVisibleHandler method = new SetCtrlVisibleHandler(SetCtrlVisibleMethod);
parentForm.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlVisibleMethod(ctrl, value);
}
}
private static void SetCtrlVisibleMethod(Control ctrl, bool value)
{
try
{
ctrl.Visible = value;
}
catch { }
}
private delegate void SetCtrlTagHandler(Control ctrl, string value);
public static void SetCtrlTag(Form parentForm, Control ctrl, string value)
{
if (parentForm.InvokeRequired)
{
SetCtrlTagHandler method = new SetCtrlTagHandler(SetCtrlTagMethod);
parentForm.BeginInvoke(method, new object[] { ctrl, value });
}
else
{
SetCtrlTagMethod(ctrl, value);
}
}
private static void SetCtrlTagMethod(Control ctrl, string value)
{
try
{
ctrl.Tag = value;
}
catch { }
}
}
}
运行截图:

wifi共享小工具的更多相关文章
- win7建wifi 热点,附wifi小工具
首先申明:1)以下操作均在管理员身份下操作,其他用户下请亲测. 2)具备无线网卡,并且已经安装好了驱动. 1.打开命令行:输入netsh wlan set hostedn ...
- python版本wifi共享工具
原先不知道win7系统也可以当作无线路由器,既然知道了这个东西那么就搞搞了 使用python写的一个wifi共享工具,还不够完善,有些功能还没做(说明:internet共享连接需要手动设置)..... ...
- 2014年Windows平台软件推荐:神器小工具(骨灰级
原文 http://www.wtoutiao.com/a/120621.html 底层工具 “If you know how to use Process Monitor competently, ...
- Windows平台软件推荐:神器小工具(骨灰级)
底层工具 "If you know how to use Process Monitor competently, people of both sexes will immediately ...
- .NET Core 跨平台资源监控库及 dotnet tool 小工具
目录 简介 dotnet tool 体验 CZGL.SystemInfo SystemPlatformInfo ProcessInfo 内存监控 NetworkInfo DiskInfo 简介 CZG ...
- ContentProvider域名替换小工具
开发项目域名想怎么换就怎么换,就是这么任性! 这是一个很有意思的小工具! 这是一个方便开发人员和测试人员的小工具!! 吐槽: 一直在做Android开发,一直总有一个问题存在:做自己公司的apk开发时 ...
- 偷懒小工具 - SSO单点登录通用类(可跨域)
写在前面的话 上次发布过一篇同样标题的文章.但是因为跨域方面做得不太理想.我进行了修改,并重新分享给大家. 如果这篇文章对您有所帮助,请您点击一下推荐.以便有动力分享出更多的"偷懒小工具&q ...
- Android抓包方法(三)之Win7笔记本Wifi热点+WireShark工具
Android抓包方法(三) 之Win7笔记本Wifi热点+WireShark工具 前言 做前端测试,基本要求会抓包,会分析请求数据包,查看接口是否调用正确,数据返回是否正确,问题产生是定位根本原因等 ...
- 八款Android 开发者必备的小工具
Photo from https://www.airpair.com 在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大 ...
随机推荐
- WebAPI使用多个xml文件生成帮助文档(转)
http://www.cnblogs.com/idoudou/p/xmldocumentation-for-web-api-include-documentation-from-beyond-the- ...
- [CareerCup] 9.6 Generate Parentheses 生成括号
9.6 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-p ...
- 运用Java对微信公众平台二次开发技术——开发者模式接入
当初我在这碰到了很多问题,市面上以及网络上的资料特别少,所以当初碰了很多壁,所以现在跟大家分享一下,如何用Java,对微信公众平台进行二次开发. 一.开发预备知识: 最基本的JavaSE与JavaWe ...
- Bootstrap3.0学习第二十一轮(JavaScript插件——工具提示)
详情请查看http://aehyok.com/Blog/Detail/27.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 将Image转化为BufferImage
public class BufferedImageBuilder { private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE ...
- beta版本项目冲刺
项目冲刺第一天 项目冲刺第二天 项目冲刺第三天 项目冲刺第四天 项目冲刺第五天 项目冲刺第六天 项目冲刺第七天
- java连接sql server2000/2005
接触Java或者JSP,难免会使用到数据库SQL Server 2000/2005(我使用2005标准版[9.0.3054]测试),经过自己的搜索和研究,使用JDBC连接SQL Server成功,特此 ...
- Cellphone Typing 字典树
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Ori ...
- Mysql-字段类型
首先统计所有,以表格查看 数字类型 列类型 需要的存储量 TINYINT 1 字节 SMALLINT 2 个字节 MEDIUMINT 3 个字节 INT 4 个字节 INTEGER 4 个字节 BIG ...
- Cocos2d-X3.0 刨根问底(七)----- 事件机制Event源码分析
这一章,我们来分析Cocos2d-x 事件机制相关的源码, 根据Cocos2d-x的工程目录,我们可以找到所有关于事件的源码都存在放在下图所示的目录中. 从这个event_dispatcher目录中的 ...