Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi!

We have a requirement to start few processes before accessing our application.

One way to do this is to make a batch file and run it automatically during windows startup.

Another way, which we prefer doing, is to start these processes via WindowsService, which can be started and stopped via our application interface.

Question thus is:
Using "WindowsService" project in VS/C#, can we call Process.Start() inside the OnStart() method of a WindowsService? Doing so in our code does not start the intended process. Are we missing something here?

Thanks for your time.
Posted

Completely wrong approaches. About the worst way to do this is to start user-mode applications from a service.

If your services are installed on the machine and setup to start Automatic, then they'll start when Windows starts.

If they are setup manually, then you can start/stop them right from your application, provided the users have the permissions to do so.

On Windows 7, you can also setup triggers to start services. I haven't looked into this at all, so you'll have to do the research, but your application should be able to start the services via a trigger, which should not need user permissions to do so.
 
Share this answer
 
Comments
#realJSOP 3-Apr-11 9:17am    
5 - Proposed as answer
TSKNaidu 4-Apr-11 8:45am    
Thanks for taking time to reflect on the question.

Are you suggesting that it is not advisable to start out-of-process servers (executables) from a windows service? Can you pl be specific why it is not?

Appreciate your time.
Dave Kreskowiak 4-Apr-11 19:07pm    
Yes, starting user-mode applications from a windows service is problematic at best. Services run no matter is anyone is logged into the machine or not. Also, it is entirely possible to have multiple people logged in on the machine at the same time.

If your application requires some service to run, those services should not depend on nor launch any other applications. They should be able to exist completly on their own. The application itself should start any services that it requires, not the other way around.
Sergey Alexandrovich Kryukov 5-Apr-11 1:01am    
Dave, there is more to it, please see my Answer.
--SA
TSKNaidu 5-Apr-11 9:13am    
Thanks Dave for taking time to bring clarity to the issue posted.

Coming back to our requirement and as mentioned in our question (option 2), we intend to start few out-of-process servers (apps) as windows services.

And, you are suggesting to better start these apps directly from our application.

This leaves us with the first option (bundle these apps into a batch file and run the batch file).

While still technically unclear about why these apps cannot be "automated" to run without our application, I looked around for a "container" that could possibly run these apps as Windows Service.

And, I would like to share with you the following links that throws more light on how to run an external process as a windows service:

1. http://support.microsoft.com/kb/251192

2. http://www.firedaemon.com/download-firedaemon.php

3. http://www.instantfundas.com/2008/08/how-to-run-windows-applications-as.html

Appreciate your time to address our question.

best regards.

You probably do not understand what a Windows Service is.
Let's not mix up different things. It's quite possible to develop some application which can start either as service or as an interactive application. This is actually very useful, for debugging, for example. I do use this approach and enjoy its robustness.

The problem is different. When you manage to do that, this is like having two application in one. Even it they share some code (which is the main purpose of such design), this is really two different application. If you run such application through System.Diagnostics.Process.Run, it is not a Windows Service by definition. If you run it via Service Controller, it is not an interactive application — by definition. These two modes never run at the same time.

One useful hint: see the property System.Environment.UserInteractive.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900