.NET 4:进程。开始使用凭据返回空输出
我从ASP.NET运行一个外部程序:.NET 4:进程。开始使用凭据返回空输出,.net,.net-4.0,process.start,.net,.net 4.0,Process.start,我从ASP.NET运行一个外部程序: var process = new Process(); var startInfo = process.StartInfo; startInfo.FileName = filePath; startInfo.Arguments = arguments; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; //startInfo.RedirectStand
var process = new Process();
var startInfo = process.StartInfo;
startInfo.FileName = filePath;
startInfo.Arguments = arguments;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
//startInfo.RedirectStandardError = true;
process.Start();
process.WaitForExit();
Console.Write("Output: {0}", process.StandardOutput.ReadToEnd());
//Console.Write("Error Output: {0}", process.StandardError.ReadToEnd());
这段代码一切正常:执行外部程序并处理。StandardOutput.ReadToEnd()返回正确的输出
但是在我在process.Start()之前添加这两行之后(在另一个用户帐户的上下文中运行程序):
程序未执行,process.StandardOutput.ReadToEnd()返回空字符串。不会引发异常。
用户名和安全密码正确(如果凭据不正确,将引发异常)
如何在另一个用户帐户的上下文中运行程序?
环境:.NET 4,Windows Server 2008 32位
UPD:
该应用程序在ASP.NET development server+Windows 7下工作正常,但在IIS 7+Windows server 2008 Web版上失败
UPD2:
在事件日志中找到:
故障应用程序cryptcp.exe,版本3.33.0.0,时间戳0x4be18460,故障模块kernel32.dll,版本6.0.6002.18005,时间戳0x49e03821,异常代码0xc0000142,故障偏移量0x00009eed,进程id 0xbf4,应用程序启动时间0x01caf1b91f5b851a
cryptcp.exe是外部应用程序的名称。查看,建议将其他一些项目配置为作为其他用户正确启动应用程序
private readonly StringBuilder outputText = new StringBuilder();
private readonly StringBuilder errorText = new StringBuilder();
。
.
您启动的应用程序可能需要加载其配置文件(默认情况下,不会加载)。您是否尝试将LoadUserProfile属性设置为true?我意识到这是不久前提出的问题,但我遇到了相同的问题,并在该网站上找到了解决方案: 在“应用程序未能正确初始化”部分下应用解决方案为我修复了它
希望这将节省一些其他人的时间和挫折 谢谢,评论不错。但这个问题解决了另一个问题。我将评论错误输出重定向。另一方面,通过搜索相同的错误偏移量和kernel32.dll发现的这个问题可能表明,一旦在IIS下运行,这是一个无法解决的问题-cryptcp.exe必须希望以某种方式与桌面交互(根据我的理解),那么,修复是什么意思?链接的站点已关闭。
private readonly StringBuilder outputText = new StringBuilder();
private readonly StringBuilder errorText = new StringBuilder();
process.OutputDataReceived += delegate(
object sendingProcess,
DataReceivedEventArgs outLine)
{
if (!string.IsNullOrEmpty(outLine.Data))
{
outputText.AppendLine(outLine.Data);
}
};
process.ErrorDataReceived += delegate(
object sendingProcess,
DataReceivedEventArgs errorLine)
{
if (!string.IsNullOrEmpty(errorLine.Data))
{
errorText.AppendLine(errorLine.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine(errorText.ToString());
Console.WriteLine(outputText.ToString());