views:

4007

answers:

4

I am trying to start an external process from a .NET Windows service. In the past I have used the Process.Start() overload that takes the executable path and a command line string. This works. But now I would like to start the process and have it run in the context of a particular user. So I call this version of Start()

public static Process Start(
    string fileName,
    string userName,
    SecureString password,
    string domain)

However, when I call the method, the application I am trying to run generates an unhandled exception 'The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.'

I have tried to start different applications and they all generate the same exception. I have run the code outside of the Windows service and the application starts correctly.

So is there a way to get this to work in a Windows service?

A: 

Use Filemon and see if it is trying to open a config file and not finding it. I once had this error due to a malformed config.

Otávio Décio
The application is a simple Win32 application (i.e. no config files).
jmatthias
+2  A: 

Maybe the user has to have, "logon as a service" security right. This is done with the "local security policy" application. And/or "logon as a batch job".

Igal Serban
If it works when not run in a service, it's usually a permissions problem.
bryanbcook
+1  A: 

This is just a shot in the dark, but perhaps you can try to run the Windows Service in Interactive mode. If that works, though, this can't be done in Windows Vista (because of Session 0 Isolation).

configurator
+2  A: 

This is very similar to this question here. The answer is usually due to security issues with the desktop and window station in which the process is being run. See this article for an explanation and some sample code.

Stephen Martin