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共享小工具的更多相关文章

  1. win7建wifi 热点,附wifi小工具

    首先申明:1)以下操作均在管理员身份下操作,其他用户下请亲测.                2)具备无线网卡,并且已经安装好了驱动. 1.打开命令行:输入netsh wlan set hostedn ...

  2. python版本wifi共享工具

    原先不知道win7系统也可以当作无线路由器,既然知道了这个东西那么就搞搞了 使用python写的一个wifi共享工具,还不够完善,有些功能还没做(说明:internet共享连接需要手动设置)..... ...

  3. 2014年Windows平台软件推荐:神器小工具(骨灰级

    原文  http://www.wtoutiao.com/a/120621.html 底层工具 “If you know how to use Process Monitor competently, ...

  4. Windows平台软件推荐:神器小工具(骨灰级)

    底层工具 "If you know how to use Process Monitor competently, people of both sexes will immediately ...

  5. .NET Core 跨平台资源监控库及 dotnet tool 小工具

    目录 简介 dotnet tool 体验 CZGL.SystemInfo SystemPlatformInfo ProcessInfo 内存监控 NetworkInfo DiskInfo 简介 CZG ...

  6. ContentProvider域名替换小工具

    开发项目域名想怎么换就怎么换,就是这么任性! 这是一个很有意思的小工具! 这是一个方便开发人员和测试人员的小工具!! 吐槽: 一直在做Android开发,一直总有一个问题存在:做自己公司的apk开发时 ...

  7. 偷懒小工具 - SSO单点登录通用类(可跨域)

    写在前面的话 上次发布过一篇同样标题的文章.但是因为跨域方面做得不太理想.我进行了修改,并重新分享给大家. 如果这篇文章对您有所帮助,请您点击一下推荐.以便有动力分享出更多的"偷懒小工具&q ...

  8. Android抓包方法(三)之Win7笔记本Wifi热点+WireShark工具

    Android抓包方法(三) 之Win7笔记本Wifi热点+WireShark工具 前言 做前端测试,基本要求会抓包,会分析请求数据包,查看接口是否调用正确,数据返回是否正确,问题产生是定位根本原因等 ...

  9. 八款Android 开发者必备的小工具

    Photo from https://www.airpair.com 在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大 ...

随机推荐

  1. 七种css方式让一个容器水平垂直居中

    阅读目录 方法一:position加margin 方法二: diaplay:table-cell 方法三:position加 transform 方法四:flex;align-items: cente ...

  2. 通过数据库方式访问excel 2007及其以后(xlsx)文件的连接字符串

    sqlconn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\test3.xls;Extended Properties=&q ...

  3. IOS开发之—— Core Foundation对象与OC对象相对转换的问题

    对ARC盲目依赖的同学: 1过度使用block后,无法解决循环引用问题 2遇到底层Core Foundation对象,需要自己手工管理它们的引用计数时,显得一筹莫展 first:对于底层Core Fo ...

  4. UIAccessibilityElement

    UIaccessibilityElement类封装的项目信息对一些特殊的人可见,默认情况下是不可访问的.例如,一个图标或文字图像不会自动访问,因为它没有继承的UIView(或UIControl).一个 ...

  5. python机器学习《回归 一》

    唠嗑唠嗑 依旧是每一次随便讲两句生活小事.表示最近有点懒,可能是快要考试的原因,外加这两天都有笔试和各种面试,让心情变得没那么安静的敲代码,没那么安静的学习算法.搞得第一次和技术总监聊天的时候都不太懂 ...

  6. 20145215实验五 Java网络编程及安全

    20145215实验五 Java网络编程及安全 实验内容 掌握Socket程序的编写: 掌握密码技术的使用: 设计安全传输系统. 实验步骤 本次实验我的结对编程对象是20145208蔡野,我负责编写客 ...

  7. NetBios网络基础及编程

    开始学习(算是复习)网络编程了,第一个就是局域网的netbios协议编程. 首先了解一下什么是netbios:IBM公司为PC-Network开发的一套网络标准.,NetBIOS最广泛的应用之一就是对 ...

  8. WPF ListView DoubleClick

    <ListView   x:Name="TrackListView"  MouseDoubleClick="MouseDoubleClick"       ...

  9. Windows Azure 名词定义(Glossary)

    Glossary(名词) Definition(定义) Availability Set 可用性组 refers to two or more Virtual Machines deployed ac ...

  10. 并行程序设计模式--Master-Worker模式

    简介 Master-Worker模式是常用的并行设计模式.它的核心思想是,系统有两个进程协议工作:Master进程和Worker进程.Master进程负责接收和分配任务,Worker进程负责处理子任务 ...