Reputation: 6518
My application is executing MsBuild.exe using Process.Start();
running as another user. The process is running as a service. When executing the process instantly fails and returns an error code -1073741502
.
Run as a service
and Impersonate another user
1073741502
??(!!) Closest thing i've found is this.Example code:
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;
}
Any help would be really appreciated. Seems to be a permissions/local security policy issue, but without knowing more it feels like i've reached the "definition of insanity" point of my troubleshooting where i'm just repeating the same actions expecting a different result.
When investigating the Event logs I see the following exception (vague as hell):
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:
Upvotes: 1
Views: 1505
Reputation: 3520
According to this thread ( Why is this process crashing as soon as it is launched? ), starting a process from a service may result in the native CreateProcessWithLogonW
API call which seems to be not working from a service.
I just found this thread because I think I'm facing a similar issue but with the powershell start-process commandlet running in a service (which probably make use of CreateProcessWithLogonW
internally.
Upvotes: 1