473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

c# service unable to spawn exe

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

Oct 18 '06 #1
4 5695
Hello richie,

This problem is arised several times
See there http://groups.google.com/group/micro...4abb972698ae09

rHi Everyone
r>
rI have a problem with windows service I wrote which spawns a win32
rprogram.
rthe code in question looks like this:
rmyProcess = new Process();
rmyProcess.StartInfo.FileName = GetInstallPath() + "\\my.exe";
rmyProcess.StartInfo.CreateNoWindow = false;
rmyProcess.Start();
rSome users (not all) get access denied immediately after calling
rstart on the process.
r>
rThe service is installed to run under the local system account.
r>
rIf the account is changed to run under the local user account there
ris no problem.
r>
rThis is perplexing cos surely the local system account has the
rhighest privileges.
r>
rAny ideas?
r>
rI should say the exe is local and not on mapped network drive.
r>
rCheers
r>
rRichard
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
Oct 18 '06 #2

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/de...withlogonw.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

Oct 19 '06 #3
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

"richie" <ri*************@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
>
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/de...withlogonw.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

Oct 19 '06 #4
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

Oct 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
15
by: Chakkaradeep | last post by:
Hi all, i have written a Service,now i want to execute another application (for eg;calc.exe) in the service....how will i perform it??... i tried using this.... /**************Executing a...
9
by: Adam Klobukowski | last post by:
Hello I've written a small C# program that uses VFPOLEDB it is working perfectly. Then, I redesigned it to work as service (as described in...
3
by: Paul | last post by:
Hi all. Can someone provide some help on the following as there seems to be many different methods of acheiving the same outcome. Basically I am trying to develop a web service which will...
5
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void...
3
by: Rob R. Ainscough | last post by:
I have a Windows Service with a timer that use the .NET 2.0 Shell command. The Shell command returns a non-zero number but Task Manager shows the shelled exe running but there is NO visible...
8
by: pigeonrandle | last post by:
Hi, I am writing a server application and would like to know what you experts think i should write it as. I would like (ie need) it to have a visual interface, hence the question, "Should i write...
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
7
by: Laszlo Nagy | last post by:
Hello, I have a win32 service written in Python that starts a plain application, written in Python. The win32 service tries to launch the application in a while loop and logs the return value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.