• 大小: 215KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-05
  • 语言: C#
  • 标签: C#  CMD  模拟  有点bug  

资源简介

一同学用C#写的模拟cmd命令行的界面,基本功能都能实现,唯一缺点是像netsh等这种有后续命令的命令输出是有点bug,但只要命令正确,不影响正常工作

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;


namespace wincmd
{
    public partial class Form1 : Form
    {
        #region 私有变量
        private StreamReader reader;
        private StreamWriter writer;
        private delegate void AppendRichText(string str);
        private Process p;
        private Thread t;
        #endregion
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            t = new Thread(new ThreadStart(ExecuteCMD));
            t.Start();
            this.richTextBox1.AppendText(“^_^ 开始运行 O(∩_∩)O \n\n“);
            Thread.Sleep(100);

        }

        private void button1_Click(object sender EventArgs e)
        {
            string cmd = this.textBox1.Text;
            this.textBox1.Text = ““;
            writer.WriteLine(cmd);


        }
        private void ExecuteCMD()
        {
            p = new Process();
            p.StartInfo = new ProcessStartInfo();
            p.StartInfo.FileName = “cmd.exe“;
            //p.StartInfo.Arguments = “-a -p tcp“;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            reader = p.StandardOutput;
            writer = p.StandardInput;

            while (true)
            {
                if (reader.EndOfStream) break;
                string cmdoutput = reader.ReadLine();
                this.Invoke(new AppendRichText(AppendText) cmdoutput);
                
            }
            MessageBox.Show(“process end“);
           
        }
        private void AppendText(string text)
        {
            this.richTextBox1.AppendText(text + “\n“);
        }

        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            t.Abort();
            if(!p.HasExited)p.Kill();


        }

        private void textBox1_TextChanged(object sender EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender EventArgs e)
        {

        }

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1466  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.application

     文件      20480  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.exe

     文件       2120  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.exe.manifest

     文件      30208  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.pdb

     文件     423936  2009-05-17 13:28  wincmd\wincmd\bin\Debug\wincmd.publish\setup.exe

     文件       5255  2009-05-17 13:28  wincmd\wincmd\bin\Debug\wincmd.publish\wincmd.application

     文件      20480  2009-05-17 13:28  wincmd\wincmd\bin\Debug\wincmd.publish\wincmd_1_0_0_1\wincmd.exe.deploy

     文件       5858  2009-05-17 13:28  wincmd\wincmd\bin\Debug\wincmd.publish\wincmd_1_0_0_1\wincmd.exe.manifest

     文件       1466  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.vshost.application

     文件       5632  2005-12-08 14:51  wincmd\wincmd\bin\Debug\wincmd.vshost.exe

     文件       2120  2009-06-03 23:54  wincmd\wincmd\bin\Debug\wincmd.vshost.exe.manifest

     文件       2494  2009-06-03 23:54  wincmd\wincmd\Form1.cs

     文件       4814  2009-06-03 18:48  wincmd\wincmd\Form1.Designer.cs

     文件       5814  2009-06-03 18:48  wincmd\wincmd\Form1.resx

     文件       1466  2009-06-03 23:54  wincmd\wincmd\obj\Debug\wincmd.application

     文件        842  2009-06-03 23:53  wincmd\wincmd\obj\Debug\wincmd.csproj.GenerateResource.Cache

     文件      20480  2009-06-03 23:54  wincmd\wincmd\obj\Debug\wincmd.exe

     文件       2120  2009-06-03 23:54  wincmd\wincmd\obj\Debug\wincmd.exe.manifest

     文件        180  2009-06-03 23:53  wincmd\wincmd\obj\Debug\wincmd.Form1.resources

     文件      30208  2009-06-03 23:54  wincmd\wincmd\obj\Debug\wincmd.pdb

     文件        180  2009-05-16 13:21  wincmd\wincmd\obj\Debug\wincmd.Properties.Resources.resources

     文件        383  2009-06-03 23:54  wincmd\wincmd\obj\wincmd.csproj.FileList.txt

     文件       1079  2009-05-21 20:44  wincmd\wincmd\obj\wincmd.csproj.FileListAbsolute.txt

     文件        465  2009-05-16 13:14  wincmd\wincmd\Program.cs

     文件       1184  2009-05-16 13:14  wincmd\wincmd\Properties\AssemblyInfo.cs

     文件       2868  2009-05-16 13:14  wincmd\wincmd\Properties\Resources.Designer.cs

     文件       5612  2009-05-16 13:14  wincmd\wincmd\Properties\Resources.resx

     文件       1091  2009-05-16 13:14  wincmd\wincmd\Properties\Settings.Designer.cs

     文件        249  2009-05-16 13:14  wincmd\wincmd\Properties\Settings.settings

     文件       4401  2009-05-17 13:29  wincmd\wincmd\wincmd.csproj

............此处省略18个文件信息

评论

共有 条评论