【发布时间】:2009-06-24 16:00:40
【问题描述】:
我正在尝试从 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
提前致谢,
埃泽奎尔
【问题讨论】:
-
忘了补充,我用的是 W2K8 和 IIS7
-
请说出你得到的“错误代码”。更好的是,通过在捕获 ex 后发布 ex.ToString() 的结果来发布完整的异常,包括所有 InnerException。
-
另外,编辑你的问题,不要离开 cmets。
-
你的意思是 ExitCode = -1066598274 吗?
-
我知道这已经很老了,但是您的代码中有“管理员”拼写错误,不确定它是否会有所作为。