a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

C#中調(diào)用命令行cmd開啟wifi熱點的實例代碼

2020-01-24 03:28:40
字體:
供稿:網(wǎng)友

要點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


要點2:在C#中調(diào)用cmd.exe命令行

復(fù)制代碼 代碼如下:

       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)外殼進程啟動程序
            p.StartInfo.UseShellExecute = false;
            //可能接受來自調(diào)用程序的輸入信息
            //重定向標(biāo)準(zhǔn)輸入
            p.StartInfo.RedirectStandardInput = true;
            //重定向標(biāo)準(zhǔn)輸出
            p.StartInfo.RedirectStandardOutput = true;
            //重定向錯誤輸出
            p.StartInfo.RedirectStandardError = true;
            //不顯示程序窗口
            p.StartInfo.CreateNoWindow = true;
            //啟動程序
            p.Start();
            //睡眠1s。
            System.Threading.Thread.Sleep(1000);
            //輸入命令
            p.StandardInput.WriteLine(str);
            //一定要關(guān)閉。
            p.StandardInput.WriteLine("exit");
        }


詳細的代碼如下:

復(fù)制代碼 代碼如下:

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;

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

        }
    }
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产精品不卡视频 | 一区二区日韩 | 国产日韩精品一区二区 | 国产青草视频在线观看视频 | 国产中文字幕亚洲 | 一区二区视频网站 | 日av一区| 久久精品欧美一区二区三区麻豆 | 色综合激情 | 黄色av网页| 日韩在线免费观看网站 | 夜夜夜久久久 | 91久久国产综合久久 | 亚洲 中文 欧美 日韩在线观看 | 久久毛片 | 亚洲一区二区免费在线观看 | 久久精品中文 | 精品国产乱码久久久久久蜜柚 | 国产免费拔擦拔擦8x高清 | 中国国产一级毛片 | 国产中文字幕一区二区 | 日本三级视频在线播放 | 国产日韩视频在线观看 | 国产最新视频在线 | 国产精品久久久久久久久 | 色婷婷av一区二区三区软件 | 黄色成人av | 亚洲欧美日韩国产 | 99视频网 | av在线色 | 国产一级免费在线观看 | 久久高清亚洲 | 男人天堂亚洲天堂 | 三级av网站| 福利社午夜影院 | 婷婷激情综合 | 欧美精品一区二 | 成 人 免 费 网 站 | 欧美日韩午夜 | 天天色天天看 | 日日噜噜噜夜夜爽爽狠狠小说 |