日期:2014-05-18  浏览次数:20439 次

asp.net执行cmd命令
我想在网站里执行cmd的操作.
举个简单的例子就是
一个输入框.输入ip之后点击一按钮.在以显示区域显示ping值之类的信息
请问要做到这样需要用到哪方面的东西
上面说的只是个例子.我就是想执行cmd操作 图形界面化而已.
谢谢

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(ExeCommand("ping 192.168.155.133"));
}

public string ExeCommand(string commandText)
{
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;
try
{
p.Start();
p.StandardInput.WriteLine(commandText);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
------解决方案--------------------
using System.Net;
AJAX
------解决方案--------------------
友情UP!

JF
------解决方案--------------------
在Asp.Net中执行cmd可以使用Process 或者是WMI,但是如果想返回执行的相关信息就没有办法了。