我的应用程序正在使用Process.Start();
作为另一个用户运行来执行MsBuild.exe。该过程作为服务运行。执行过程立即失败并返回错误代码-1073741502
。
Run as a service
和Impersonate another user
1073741502
??(!!)我发现的最近的东西是this。示例代码:
void Main(){
var startInfo = new ProcessStartInfo
{
FileName = path,
Arguments = args,
WorkingDirectory = workingPath,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
LoadUserProfile = true,
Domain = System.Environment.MachineName,
UserName = creds.Username,
Password = generateSecureString(creds.Password)
};
var process = Process.Start(startInfo);
process.OutputDataReceived += process_OutputDataReceived;
process.ErrorDataReceived += process_OutputDataReceived;
process.Exited += process_Exited;
process.EnableRaisingEvents = true;
process.WaitForExit();
}
internal void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}
void process_Exited(object sender, EventArgs e)
{
var process = ((Process) sender);
Console.WriteLine("Process has finished execution, exit code '{0}'.", process.ExitCode);
}
private SecureString generateSecureString(string password)
{
var secure = new SecureString();
foreach (var c in password.ToCharArray())
{
secure.AppendChar(c);
}
return secure;
}
任何帮助都会非常感激。似乎是一个权限/本地安全策略问题,但不知道更多,感觉就像我已经达到了“疯狂的定义”我的故障排除点,我只是重复相同的操作,期待不同的结果。
在调查事件日志时,我看到以下异常(模糊不清):
Faulting application name: msbuild.exe, version: 12.0.31101.0, time stamp: 0x545443d5
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17668, time stamp: 0x54c846bb
Exception code: 0xc0000142
Fault offset: 0x0009e052
Faulting process id: 0x3e8
Faulting application start time: 0x01d065cdac34cc77
Faulting application path: C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild.exe
Faulting module path: KERNELBASE.dll
Report Id: ecce8b9d-d1c0-11e4-80d7-00155d611ee6
Faulting package full name:
Faulting package-relative application ID:
答案 0 :(得分:1)
根据此线程(Why is this process crashing as soon as it is launched?),从服务启动进程可能会导致本机CreateProcessWithLogonW
API调用似乎无法从服务中运行。
我刚刚找到了这个帖子,因为我认为我面临着类似的问题,但是在服务中运行的powershell start-process命令行开关(可能在内部使用CreateProcessWithLogonW
。