国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

C#中調(diào)用命令行cmd開(kāi)啟wifi熱點(diǎn)的實(shí)例代碼

2020-01-24 03:28:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

要點(diǎn)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


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


詳細(xì)的代碼如下:

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

        }
    }
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 茌平县| 额济纳旗| 子洲县| 榆中县| 北流市| 龙岩市| 徐闻县| 西乌珠穆沁旗| 永和县| 新化县| 贡山| 双城市| 福泉市| 邢台市| 明光市| 仪征市| 松阳县| 鸡东县| 河津市| 保定市| 沙洋县| 东辽县| 巴彦淖尔市| 乐平市| 同仁县| 东莞市| 琼中| 霍邱县| 株洲市| 元氏县| 通辽市| 西乌珠穆沁旗| 荔波县| 寿宁县| 饶阳县| 务川| 伊金霍洛旗| 元氏县| 玛纳斯县| 醴陵市| 鄢陵县|