日期:2014-05-17 浏览次数:20605 次
/// <summary>
/// 按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnGetTest_Click(object sender, EventArgs e)
{
GetTest();
}
private void GetTest()
{
if (File.Exists( txtSName.Text.Trim()))
{
Process consoleProcess = new Process();
//获取文件路径 比如 c:\PS\app0.bat,
string batFilePath = txtSName.Text;
//我想让程序执行这个bat文件,停某个服务,app0.bat文件内容为:net stop appMgmt
consoleProcess.StartInfo.FileName = batFilePath;
consoleProcess.StartInfo.UseShellExecute = false;
consoleProcess.StartInfo.RedirectStandardInput = true;
consoleProcess.StartInfo.RedirectStandardOutput = true;
consoleProcess.Start();
StreamReader streamReader = consoleProcess.StandardOutput;
txtResult.Text = streamReader.ReadToEnd();//输出结果
}
else
{
txtResult.Text = "文件不存在";
}
}