From: matteo on
Hi all,

I turned my application in a common user-mode Windows service, which
starts at boot time.
It works fine, but it seems I can send only predefined messages to my
service: install, uninstall, start, stop, pause, continue...That's
good, but I need also to send "customized messages" to the service, to
trigger some special actions in the service.

Someone knows how to interact with a service by sending user-defined
commands/signals?


thank you all!

matt

From: chris_doran on

matteo wrote:
> Hi all,
>
> I turned my application in a common user-mode Windows service, which
> starts at boot time.
> It works fine, but it seems I can send only predefined messages to my
> service: install, uninstall, start, stop, pause, continue...That's
> good, but I need also to send "customized messages" to the service, to
> trigger some special actions in the service.
>
> Someone knows how to interact with a service by sending user-defined
> commands/signals?
>
>
> thank you all!
>
> matt

You can send user-defined control codes in range 128-255 via
ControlService(). The only way I know for anything bigger is to use
sockets, shared memory, files, ...

Chris

From: Scott McPhillips [MVP] on
matteo wrote:
> Hi all,
>
> I turned my application in a common user-mode Windows service, which
> starts at boot time.
> It works fine, but it seems I can send only predefined messages to my
> service: install, uninstall, start, stop, pause, continue...That's
> good, but I need also to send "customized messages" to the service, to
> trigger some special actions in the service.
>
> Someone knows how to interact with a service by sending user-defined
> commands/signals?

CreateNamedPipe()

or you can use winsock to open a TCP/IP connection.

--
Scott McPhillips [VC++ MVP]

From: matteo on
I try to do this, but when I send my user-defined command the service
stops suddenly...

#define SERVICE_CONTROL_CUSTOM 129

....

scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

service = OpenService(scm,
ServiceName,

SERVICE_ALL_ACCESS|SERVICE_USER_DEFINED_CONTROL);
if (!service) ErrorHandler("OpenService", GetLastError());

....

cout << "Custom command..." << endl;
SUCCESS = ControlService(service, SERVICE_CONTROL_CUSTOM, &status);

and

void ServiceCtrlHandler(DWORD controlCode)
{
DWORD currentState = 0;
BOOL success;
switch(controlCode)
{
. . .
case SERVICE_CONTROL_CUSTOM:
//fai azione personalizzata!!!!
//fopen("c:\\custom1.txt","w");

currentState = SERVICE_RUNNING;
break;
...
}

if I get the service status, after sending the command, it results
STOPPED...

any ideas?

From: Paul on

<chris_doran(a)postmaster.co.uk> wrote in message
news:1143727788.265166.265900(a)t31g2000cwb.googlegroups.com...
>
> matteo wrote:
> > Hi all,
> >
> > I turned my application in a common user-mode Windows service, which
> > starts at boot time.
> > It works fine, but it seems I can send only predefined messages to my
> > service: install, uninstall, start, stop, pause, continue...That's
> > good, but I need also to send "customized messages" to the service, to
> > trigger some special actions in the service.
> >
> > Someone knows how to interact with a service by sending user-defined
> > commands/signals?
> >
> >
> > thank you all!
> >
> > matt
>
> You can send user-defined control codes in range 128-255 via
> ControlService(). The only way I know for anything bigger is to use
> sockets, shared memory, files, ...
>

I wound up using pipes to talk to my services. IIRC I tried ControlService()
and had problems with it, but I can't remember exactly why. The pipes method
isn't hard to set up, works great, and is very flexible for whatever you
need in future. Don't try to use a bidirectional pipe (ever, for anything)
but that's the only caveat.