新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:做一个Windows窗体版的DOS分析器

做一个Windows窗体版的DOS分析器

新客网 XKER.COM 2004-06-25 来源: 收藏本文
////////////////////////////////////////////////////////////////////////////////
//Author: stardicky //
//E-mail: stardicky@hotmail.com //
//QQNumber: 9531511 //
//CompanyName: Ezone International //
//Class: HBS-0308 //
//title: 做一个Windows窗体版的DOS分析器 //
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

namespace EzoneDOSApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtCmd;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.RichTextBox rtbResult;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

private Process ProcessCmdObject;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
ProcessCmdObject=new Process();

ProcessCmdObject.StartInfo.FileName="cmd.exe";

ProcessCmdObject.StartInfo.UseShellExecute=false;

ProcessCmdObject.StartInfo.RedirectStandardInput=true;

ProcessCmdObject.StartInfo.RedirectStandardOutput=true;

ProcessCmdObject.StartInfo.RedirectStandardError=true;

ProcessCmdObject.StartInfo.CreateNoWindow=true;

ProcessCmdObject.Start();


}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtCmd = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.rtbResult = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// txtCmd
//
this.txtCmd.Location = new System.Drawing.Point(0, 0);
this.txtCmd.Name = "txtCmd";
this.txtCmd.Size = new System.Drawing.Size(448, 21);
this.txtCmd.TabIndex = 0;
this.txtCmd.Text = "";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(456, 0);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 1;
this.btnOK.Text = "确认";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// rtbResult
//
this.rtbResult.Location = new System.Drawing.Point(0, 24);
this.rtbResult.Name = "rtbResult";
this.rtbResult.Size = new System.Drawing.Size(536, 424);
this.rtbResult.TabIndex = 2;
this.rtbResult.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 445);
this.Controls.Add(this.rtbResult);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.txtCmd);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "DOS分析器 - 亿众国际";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btnOK_Click(object sender, System.EventArgs e)
{
ProcessCmdObject=new Process();

ProcessCmdObject.StartInfo.FileName="cmd.exe";

ProcessCmdObject.StartInfo.UseShellExecute=false;

ProcessCmdObject.StartInfo.RedirectStandardInput=true;

ProcessCmdObject.StartInfo.RedirectStandardOutput=true;

ProcessCmdObject.StartInfo.RedirectStandardError=true;

ProcessCmdObject.StartInfo.CreateNoWindow=true;

ProcessCmdObject.Start();

ProcessCmdObject.StandardInput.WriteLine(this.txtCmd.Text.Trim());

ProcessCmdObject.StandardInput.WriteLine("exit");

this.rtbResult.Text=ProcessCmdObject.StandardOutput.ReadToEnd()+ProcessCmdObject.StandardError.ReadToEnd();
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
}
}

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐