Click to See Complete Forum and Search --> : Starting an EXE as a Win Service


Laxmi Narasimha
May 26th, 2005, 06:59 AM
I need help from you guys to write an application which is capable of start EXE when service is start. and stop that EXE when service is stop,
This EXE contains many more Threads .

suggest me with sample program or URL

Regards ...
L N Raju

Andreas Masur
May 26th, 2005, 07:02 AM
Services (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/services.asp)
How can I start a process? (http://www.codeguru.com/forum/showthread.php?t=302501)

Laxmi Narasimha
May 26th, 2005, 07:25 AM
I have gone through sites ...
i have worked with developing service (start,stop).just doing nothing,
and made changes such that when ever service is started a new thread is created and in thread i am calling "myprg.exe" with ShellExecute function
i am able to see both exe in TaskManager.
BUt what goes wrong is ... myprg.exe , i am writhing into logger the functionality it does but logger is not showing any functionality done by it just logger is created...
i am unable to understand whether myprg.exe is running or closed in middle
if any samples pls forward me..

Thank You
L N Raju

Andreas Masur
May 26th, 2005, 09:01 AM
I am not sure whether I understand...you want to create a service which in turns starts an executable? Why do you need to do this with a service in the first place? Also what kind of executable do you want to start? Services are started before anybody logs in...of course a bad situation for GUI applications... ;)

Laxmi Narasimha
May 26th, 2005, 09:31 AM
Ya Andreas Masur you are correct...ie., i need to start a service which in turn starts Executable.
Executable is ordinary c++ code which contains 10 threads .The main intension is This executable should not be killed by user( from Task Manager).This doesn't contains any harmful code just related to Telcom project which needs back end to run continously for supporting NAT issues in network.
whether services does not support huge code to be runned at the time of starting?
if so please suggest me any other option.

Thank You
L N Raju

Andreas Masur
May 26th, 2005, 09:34 AM
And why are the need for both a service and an application? From what I understand...why not using a service alone?

Laxmi Narasimha
May 26th, 2005, 10:05 AM
I tried with this option also (by keeping all the code of Executable (nearly 80 classes )in Service ). I can see service.exe in TaskManager but it doesnt do its complete functionality.
Whats wrong with that code.
Thank You
L N Raju

Andreas Masur
May 26th, 2005, 10:15 AM
Well..pretty hard to tell...I don't know exatly what the app/service is supposed to do and what of that is not working...

Laxmi Narasimha
May 27th, 2005, 09:58 AM
I am able to start service if it excute small code.

Is Huge code(executing in back end ) maybe the problem to start service.

Any sugestion Please.

Regards.
L N Raju

Wolvorine
May 27th, 2005, 02:51 PM
a way to start an executable is something like ...
Create your Service program and then inside the Thread function of yours just call the ShellExecute and give the path of an exe you want to run..so when this service will get start ur exe will be executed (be sure to call it once inside loop of thread , otherwise many instances will get open)... and second method is to start the Exe by creating a process inside the thread execute... To hide the process inside task manager u have to get its handle and hide it i think insid ecodeproject u can find this kind of code that could hide the processes inside task manager while they are running.... and one more thing when you start the service be sure to go inside Service control of windows and then check the properties of ur service and select "interact with desktop" (do this if exe dont get executed otherwise uncheck it).

this is the only way i think to start gui type exe inside service, maybe it has many other method but i dont know...hope this would help