From: JD on 30 Mar 2006 10:56 "matteo" <matteo.formica(a)gmail.com> wrote in message news:1143726028.149596.275260(a)i39g2000cwa.googlegroups.com... > 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 > Depending on the type of signal you want to send, an event is sometimes useful. Run a thread that waits on multiple objects and fire events. Of course, you don't get a lot of additional information carried along. Mike P
From: Kellie Fitton on 30 Mar 2006 13:45 Hi, You can use the function ControlServiceEx() to send controls, however, if you want a better approach to communicate with the service process in an efficient way, you should use named pipes: You can communicate with the service locally and remotely. You can have secured access methods with impersonation. You can send and receive large messages. Use the following APIs to create/handle/manage the named pipe: CreateNamedPipe() SetNamedPipeHandleState() ConnectNamedPipe() CreateFile() ReadFile() WriteFile() CloseHandle() ImpersonateNamedPipeClient() RevertToSelf() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/controlserviceex.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/createnamedpipe.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/setnamedpipehandlestate.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/connectnamedpipe.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/readfile.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/writefile.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/closehandle.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/impersonatenamedpipeclient.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/reverttoself.asp Hope these suggestions helps, Kellie.
From: chris_doran on 30 Mar 2006 17:44 matteo wrote: > 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? Hmm. Your code looks the same as mine, which works. E-mail me if you want a copy. Chris
From: matteo on 3 Apr 2006 05:54
thank you all, I believe I'll use pipes... chris_doran(a)postmaster.co.uk ha scritto: > matteo wrote: > > 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? > > Hmm. Your code looks the same as mine, which works. E-mail me if you > want a copy. > > Chris |