Windows SDK - C# - 调试进程退出,错误代码为-1073741502

时间:2011-03-20 05:32:32

标签: c# windows mercurial process winapi

短片

当进程退出错误代码-1073741502时,如何确定哪个DLL无法加载(以及可能的原因)?

LONG VERSION

我正在尝试为Mercurial编写一个pretxnchangegroup挂钩,作为该挂钩的一部分,我需要获取运行该命令的输出:

hg log

我用来启动和运行hg.exe进程的代码如下:

string Command = "log";
Process p = new Process();

ProcessStartInfo psi = p.StartInfo;
p.StartInfo.FileName = @"C:\Program Files (x86)\Mercurial\hg.exe";

psi.CreateNoWindow = true;
psi.LoadUserProfile = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;

psi.WorkingDirectory = Environment.CurrentDirectory;

p.StartInfo.Arguments = Command;


// Pass-through environment variables
psi.UserName = Properties.Settings.Default.HG_User;
psi.Domain = Properties.Settings.Default.HG_Domain;
psi.Password = new System.Security.SecureString();

foreach (char c in Properties.Settings.Default.HG_Pass)
{
    psi.Password.AppendChar(c);
}

p.Start();      
p.WaitForExit();

问题是该过程一直以错误代码-1073741502退出,而不会在标准输出或标准错误上输出任何内容。经过网上的一些研究,我发现这个错误代码与应用程序无法正确初始化有关(无法找到DLL,可能?),但我不知道如何去搞清楚如何修复它。 / p>

请记住,当我通过Web推送到存储库时,会调用此挂钩(因此,IIS通过Python调用Mercurial CGI,将此程序配置为挂钩)。

在一个完全不同的Web应用程序中,我能够很好地运行HG命令,而且我也可以通过执行 runas /user:<same account as in the code> /noprofile cmd.exe然后手动输入hg命令行。

另外,如果我设置UseShellExecute = true,那么它执行得很好,但是我无法获得标准输出。我真的很想只是对Web应用程序进行Web服务调用, 能够成功执行此命令,但这是一个非常难看的解决方案。

为什么这件事没有执行的任何想法?

2 个答案:

答案 0 :(得分:4)

我认为这可能与Windows如何处理您正在产生的新流程有关 每个进程都将使用非交互式桌面内存,直到用完Windows堆,并且不能启动任何进程。

http://www.tomshardware.co.uk/forum/217729-36-application-failed-initialize-properly-0xc0000142

http://blogs.msdn.com/b/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx

答案 1 :(得分:1)

我能够通过禁用UAC来解决此问题,因此即使我不知道确切的详细信息,这听起来像是权限问题。

相关问题