Start a process as a different user from Windows Service

A

Agnes

Hi,

I am trying to start a new process as a different user from a Windows
Service.

When I start the process from a console application, it works perfectly.
But if I do the same thing from the Windows service, it gives an Application
Error: The applcation failed to initialize properly (0xc0000142).

My code looks like this:

Process p = new Process();

p.StartInfo.FileName = "somePathToThe.EXE";

p.StartInfo.Arguments = "some arguments";

p.StartInfo.UserName = "theUser@Domain";

p.StartInfo.Password = passwordInSecureString;

p.StartInfo.UseShellExecute = false;

p.Start();



Did I do something wrong? But it works when running in a console app. Is
it not allowed when running as windows service??

Thank you for your help!!



Agnes
 
S

Siva M

I have not tried but take a look at
http://weblog.gpconsulting.com/archive/2005/09/30/192.aspx

Hi,

I am trying to start a new process as a different user from a Windows
Service.

When I start the process from a console application, it works perfectly.
But if I do the same thing from the Windows service, it gives an Application
Error: The applcation failed to initialize properly (0xc0000142).

My code looks like this:

Process p = new Process();

p.StartInfo.FileName = "somePathToThe.EXE";

p.StartInfo.Arguments = "some arguments";

p.StartInfo.UserName = "theUser@Domain";

p.StartInfo.Password = passwordInSecureString;

p.StartInfo.UseShellExecute = false;

p.Start();



Did I do something wrong? But it works when running in a console app. Is
it not allowed when running as windows service??

Thank you for your help!!



Agnes
 
C

Carl Daniel [VC++ MVP]

Agnes said:
Hi,

I am trying to start a new process as a different user from a Windows
Service.

When I start the process from a console application, it works perfectly.
But if I do the same thing from the Windows service, it gives an
Application Error: The applcation failed to initialize properly
(0xc0000142).

What kind of application are you trying to start? What does it do?

-cd
 
M

Massimo

Hi,

I am trying to start a new process as a different user from a Windows
Service.

When I start the process from a console application, it works perfectly.
But if I do the same thing from the Windows service, it gives an
Application Error: The applcation failed to initialize properly
(0xc0000142).

What kind of application are you trying to start? Does it display a window
on the screen? Is it a console application? I.e. does it have any kind of
user interface?
Also: what user account is the service runing under?


Massimo
 
A

Agnes

It is a console application. It does some DB queries and updates. Then it
opens a win form which contains an axWebBrowser control for some web
navigation automation.

I use a service user account to start the service. When it creates the new
process, it starts it as another service user account.

I tried running the windows service still as the 1st user account but did
not impersonate the new process as the 2nd user account. That worked fine.
I saw from the task manager the new process was running as the 1st user
account.

But once I added the impersonate, the process failed to start up.
 
M

Massimo

It is a console application. It does some DB queries and updates. Then
it opens a win form which contains an axWebBrowser control for some web
navigation automation.

I use a service user account to start the service. When it creates the
new process, it starts it as another service user account.

Are those services configured to be able to interact with the desktop?
Otherwise they just can't open a form.
I tried running the windows service still as the 1st user account but did
not impersonate the new process as the 2nd user account. That worked
fine. I saw from the task manager the new process was running as the 1st
user account.

But once I added the impersonate, the process failed to start up.

I don't have any clue here, sorry.


Massimo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top