System.Diagnostics.Process.Start() cannot start process when called from Windows service

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?

c#
.net
windows-services
asked on Stack Overflow Jan 18, 2009 by jmatthias • edited Mar 21, 2014 by Chris Ballard

4 Answers

2

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".

answered on Stack Overflow Jan 19, 2009 by Igal Serban • edited Jan 19, 2009 by Igal Serban
2

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.

answered on Stack Overflow Apr 2, 2009 by Stephen Martin • edited May 23, 2017 by Community
1

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).

answered on Stack Overflow Jan 19, 2009 by configurator
0

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.

answered on Stack Overflow Jan 19, 2009 by Otávio Décio

User contributions licensed under CC BY-SA 3.0