////////////////////////////////////////////////////////////////////////////////
//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)
{
}
}
}