Windows Services - How to communicate with them? (update settings, etc.)

B

Bill

Hello,

I'm successfully on my way to finishing up a C# Windows Service now, but now I'm wondering how I can communicate with this service. Services examples seem to be everywhere on the internet now, but what is the best practice for communicating with them?

1) It seems like a control panel is best for setting options, but I cannot find any examples on how to make a control panel item in .NET. Can someone provide a link to an article on how to do this, or give the basic steps.

2) How can the control panel or even a WinForm C# app send messages to the service? Before I was using a service, I was sending messages between apps using RegisterWindowMessage and PostMessage. Everything I've been reading seems to indicate that user defined windows messaging (or any message for that matter) won't work with a service because it doesn't have a window to hear them. Regardless of whether I can create a control panel app or not, I need to figure out how to message between the Control Panel or Helper App and the service (like antivirus programs, backup programs, video card settings, etc. which are service based but have access through an app in the icon tray). Any suggestions, samples, or examples?

Thanks,
-Bill
 
T

Tian Min Huang

Hi Bill,

Thanks for your post. I reviewed your description carefully, and now I'd
like to share the following information with you:

1. Based on my experience, we are not able to create a control panel applet
in a .NET managed application. As you know, control panel applets are just
standard (unmanaged) DLLs with a particular set of entry points and a .cpl
extension. We have to stick to C++ or someother language that allows you to
export static entry points. I believe the following articles and samples
are helpful for creating a control panel applet:

The platform SDK has some guidance for using C++ :
http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersgu
ide/shell_adv/conpanel.asp

Control Panel Applet Framework
http://www.codeproject.com/win32/cjbcontrolpanelapplet.asp

Control Panel Applet using MFC
http://www.codeguru.com/system/ControlPanelAppletMFC.shtml

2. You can communicate with your service in whatever way suits you¡ªnamed
pipes, thought transference, sticky notes, and so on. For simple requests,
I recommend you use the unmanaed API ControlService() or
ServiceController::ExecuteCommand() in managed application to send a
user-defined control code to the service, and a .NET service can process it
in ServiceBase.OnCustomCommand() method.

ControlService
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/controlservice.asp

ServiceBase.OnCustomCommand Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemserviceprocessservicebaseclassoncustomcommandtopic.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top