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 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大 ...
随机推荐
- OAF中的面包屑(breadcrumbs)始无法显示(转)
原文地址:OAF中的面包屑(breadcrumbs)始无法显示 OAF中面包屑是一种重要的导航工具.可以提示用户抵达当前页面的路径,也可以方便的切换到之前的节点. 开始做面包屑开发的时候发现面包屑总是 ...
- 分享基于EF+MVC+Bootstrap的通用后台管理系统及架构(转)
http://www.cnblogs.com/guozili/p/3496265.html 基于EF+MVC+Bootstrap构建通用后台管理系统,集成轻量级的缓存模块.日志模块.上传缩略图模块.通 ...
- 我们为什么需要DTO?
看了几套源码,其中都有用到DTO,这篇文章主要来谈论一下DTO使用的场合及其带来的好处. 在传统的编程中,我们一般都是前台请求数据,发送到Webservice,然后WebService向数据库发出请求 ...
- 阿里云OSS NET SDK 引用示范程序
1.引入SDK bin文件,下载地址:https://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/internal/oss/0.0.4/assets/sdk/ ...
- 【Lucene实验1】构建索引
一.实验名称:构建索引 二.实验日期:2013/9/21 三.实验目的: 1) 能理解Lucene中的Document-Field结构的数据建模过程: 2) 能编针对特定数 ...
- Shadowsock搭建
搭建Shadowsocks服务端: 搭建Shadowsocks之前首先必须购买一个VPS.一般VPS提供商会给一个测试地址,购买之前最好先ping一下速度.也可以通过以下网址测试下vps网络速度: h ...
- webstorm调试Node的时候配置
点击Edit Configurations的这个的配置:(不能点击是因为目前你选中的不是项目)
- [AHOI2013]找硬币(搜索)
[Ahoi2013]找硬币 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 348 Solved: 114[Submit][Status] Descri ...
- 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会
h1. Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和合作机会 h4. Ideas to incorporat ...
- iOS开发小技巧--设置按钮圆角
方法一:代码设置 方法二:通过图形化界面