c# service unable to spawn exe

R

richie

Hi Everyone

I have a problem with windows service I wrote which spawns a win32
program.
the code in question looks like this:

myProcess = new Process();
myProcess.StartInfo.FileName = GetInstallPath() + "\\my.exe";
myProcess.StartInfo.CreateNoWindow = false;
myProcess.Start();

Some users (not all) get access denied immediately after calling start
on the process.

The service is installed to run under the local system account.

If the account is changed to run under the local user account there is
no problem.

This is perplexing cos surely the local system account has the highest
privileges.

Any ideas?

I should say the exe is local and not on mapped network drive.

Cheers

Richard
 
M

Michael Nemtsev

Hello richie,

This problem is arised several times
See there http://groups.google.com/group/micr...read/thread/7254622ee505a82a/fc4abb972698ae09

r> Hi Everyone
r>
r> I have a problem with windows service I wrote which spawns a win32
r> program.
r> the code in question looks like this:
r> myProcess = new Process();
r> myProcess.StartInfo.FileName = GetInstallPath() + "\\my.exe";
r> myProcess.StartInfo.CreateNoWindow = false;
r> myProcess.Start();
r> Some users (not all) get access denied immediately after calling
r> start on the process.
r>
r> The service is installed to run under the local system account.
r>
r> If the account is changed to run under the local user account there
r> is no problem.
r>
r> This is perplexing cos surely the local system account has the
r> highest privileges.
r>
r> Any ideas?
r>
r> I should say the exe is local and not on mapped network drive.
r>
r> Cheers
r>
r> Richard
r>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
R

richie

Thanks for the reply Michael

I also contacted Microsoft and they said:System.Diagnostics.Process.Start is calling CreateProcessWithLogonW API
under the scenes. The behavior of this API has changed in Windows XP
SP2 and Windows Server 2003:

CreateProcessWithLogonW

http://msdn.microsoft.com/library/d...n-us/dllproc/base/createprocesswithlogonw.asp

"

Windows XP SP2 and Windows Server 2003: You cannot call
CreateProcessWithLogonW from a process that is running under the
LocalSystem account, because the function uses the logon SID in the
caller token, and the token for the LocalSystem account does not
contain this SID. As an alternative, use the CreateProcessAsUser and
LogonUser functions.

"


So basically starting a process from a c# service is not going to work
when running under the local system account, which I need to do cos
some users are restricted. I could use win32 via pinvoke to circumvent
this.

But I've decided to write the service in win32 and run the code as a
thread from the service. The exe I was running is c/c++ anyway so this
is easy.

If anyone is interested a good article for writing a win32 service is
http://www.commsoft.com/services.html

Thanks again

Cheers

Richard
 
D

Dr. Jochen Manns

Im a bit upset because I'm running a service under WinXP SP2 and the
following code works quite fine to spawn another process (in this case it's
the service executable itself started as an isolated worker process
communicating with the service by serializing commands using standard input
and output):

// Create startup information
ProcessStartInfo pStart = new
ProcessStartInfo(Application.ExecutablePath, "AsChild");

// Use standard I/O
pStart.UseShellExecute = false;
pStart.RedirectStandardOutput = true;
pStart.RedirectStandardInput = true;

// Create new process
Process pNew = new Process();

// Attach
pNew.StartInfo = pStart;

// Activate it
pNew.Start();

Actually you should rethink the CreateNoWindow = False - maybe at least the
interactive access to desktop would be required. But question is: do you
really start the process with a GUI?

Jochen
 
R

richie

Hi Jochen

Thanks for the suggestion, my app has no gui. But I'll try it and let
you know.

I should point out that about 90% of our customers who installed the c#
service had no problems whatsoever. My problem is of course I need a
solution that works for all my customers.

I was really just being lazy cos I was just using the c# service as
thin wrapper.The win32 soln I've written creates a thread to run the
code I had previously in the exe. It took a morning to get it up and
running in win32 so not too much effort.

Not sure if any of that will make you feel better though.

Cheers

Richard
 

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