我正在尝试从 ASP.NET 网站运行旧的 .NET 应用程序。在阅读了 web 和 Stackoverflow(对于类似的问题)之后,我来到了以下代码。问题是我总是得到一个错误代码(我使用管理员帐户只是为了测试目的)。如果我手动运行 exe,它可以正常工作。
private void Execute(string sPath)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.UserName = "administrador";
string pass = ".............";
System.Security.SecureString secret = new System.Security.SecureString();
foreach (char c in pass) secret.AppendChar(c);
proc.StartInfo.Password = secret;
proc.StartInfo.WorkingDirectory = ConfigurationManager.AppSettings["WORKINGDIRECTORY"].ToString();
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = sPath;
proc.Start();
proc.WaitForExit();
string result = proc.StandardOutput.ReadToEnd();
Response.Write(result + " - " + proc.ExitCode);
proc.Close();
}
}
我得到的退出代码是:-1066598274 结果变量为空。没有抛出异常我正在使用带有 IIS 7.0 的 Windows 2008
提前致谢,
以西结