IIS中执行时,可能会有权限问题,应用程序池》高级设置》进程模型》标识 设置用户名和密码
protected void Button1_Click(object sender, EventArgs e)
{Response.Write(ExeCommand("d:\\qt-faststart.exe d:\\11.mp4 d:\\88.mp4"));
}
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;
}
本文介绍了一种在IIS环境中通过ASP.NET调用外部程序的方法,并解决了可能出现的权限问题。具体实现包括设置应用程序池的高级选项以指定运行账户,以及使用Process类来启动和控制外部进程。

4142

被折叠的 条评论
为什么被折叠?



