Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In my VC++ code,

I want to run the B.exe background as window service when clicking "start" button in the dialog of A.exe?

and

How can A.exe send message or send data to B.exe and receive from B.exe?

Who have any simple example?

Thank you in advance.

What I have tried:

More 2 days wasted for this program.
Posted
Updated 21-May-17 22:53pm

At first you have to install the service. To start a service programmatically use the OpenService function (Windows)[^] and the StartService function (Windows)[^]. Note that this requires that the program is executed with sufficient priviliges.

Alternatively use the Windows PowerShell (execute shell commands from your program). See Start-Service[^].

The general term for data interchange between processes is IPC (Interprocess Communications (Windows)[^]). You should read about the available methods and choose one that matches your requirements. The CodeProject article Windows IPC[^] explains some methods in detail with their advantages and disadvantages and provides example code.
 
Share this answer
 
First of all B.exe must fit the rules of a service - not every executable can run as service!!!
I would also advise to make B.exe a self installing service, so you can start and stop it from a single command line...
There are samples for such services:
Windows Services Can Install Themselves[^]
Windows Service to Host Multiple WCF Services[^]
 
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