asp.net执行cmd命令 我想在网站里执行cmd的操作.举个简单的例子就是一个输入框.输入ip之后点击一按钮.在以显示区域显示ping值之类的信息请问要做到这样需要用到哪方面的东西上面说的只是个例子.我就是想执行cmd操作 图形界面化而已.谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; } 在Asp.Net中执行cmd可以使用Process 或者是WMI,但是如果想返回执行的相关信息就没有办法了。 关于ASP.NET MVC中怎么创建一个button access中like写法 学习三层中遇到的小问题。 ???怎样得到自己本机ip地址 【高分求助】如何读取或改变在DLL中的一个变量的值? 如何把数据POST到代码绑定的asp.net页面啊? 关于一个值传递多个值到另一个页面(在线等) 求助~``高手请进..那个号没有分了..开个新好,急啊。 求救文本框不可手动修改问题进来看看!!! 关于浏览器最小化时的更新提示问题 页面中还需要管理数据库的打开和关闭吗 asp.net怎样连接SQL server2000?
{
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;
}