I have a situation occuring when launching Processes from a Windows service
_________
| | * Process 1
| Service | -------> * Process ...
|_________| * Process n
The code used by the service to do so is the following:
ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, commandlineArgs);
startInfo.WorkingDirectory = instancePath;
startInfo.UserName = userB;
startInfo.Password = passwordSecureString;
startInfo.Domain = domain;
startInfo.UseShellExecute = false;
Process process = new Process
{
StartInfo = startInfo,
EnableRaisingEvents = true,
};
process.Start();
Now, I have two accounts - for simplicity's sake, say A and B. The service is being run under the first one and starts the processes using the second one.
The following table is supposed to indicate what happens in which account constellation.
_______________
| | A | B |
|===+=====+=====|
| A | OK | X |
|---+-----+-----|
| B | X | OK |
|___|_____|_____|
...which makes me assume that the user change leads to the problem.
Details on the occuring exception:
After having read upon Error Code 142, here's what I've tried so far:
Can anyone relate to this issue?
Stephen Martin has given an explanation of what's going on here, so if you are experiencing the issue described in the original question, the following blog post may be of interest to you:
http://asprosys.blogspot.de/2009/03/perils-and-pitfalls-of-launching.html
Here, Stephen explains
Oops again, where is the process? Check the event log (or you may have received an Application Error pop-up). There should be an entry for Application Error that says that your process was the faulting application, either user32.dll or kernel32.dll was the faulting module and the exception was: 0xC0000142. There may be some minor variation in this but basically it is saying that your application could not initialize. The reason for this is that on initialization, before any application code is run, all processes are attached to a Window Station and all threads are attached to a Desktop but the user you are launching under does not have permission to access the Window Station and Desktop in which your process is being launched, ergo it can't initialize. The security descriptors for the Window Station and Desktop must be adjusted to give AllAccess permission to the user the process is being launched under. This is a devil to do directly in .Net, so you might find the security wrapper classes here useful
If you don't like using Stephen's library, you can also check the other solutions offered here (which I haven't tested yet).