Service Sample: Create and Install a Service

Click to open or copy the files for the Service sample.

The Service sample demonstrates how to create and install a service.

In this particular sample, the service merely opens a named pipe (the name defaults to \\.\pipe\simple) and waits for read and write operations to the pipe. If the pipe receives input, it creates the string:

Hello! [<input goes here>]

and sends it back to the client through the pipe.

The service can be started and stopped from the control panel Services applet, the net command, or by using the service controller utility (see MORE INFORMATION).

The service also provides command-line parameters that install, remove, or run (debug) the service as a console application.

Building SDK Samples

This sample uses the following keywords:

_stprintf; _stricmp; _tcsicmp; _tprintf; addtomessagelog; callnamedpipea; closehandle; closeservicehandle; cmddebugservice; cmdinstallservice; cmdremoveservice; commandlinetoargvw; connectnamedpipe; controlservice; createevent; createnamedpipe; createservice; deleteservice; deregistereventsource; disconnectnamedpipe; exit; formatmessage; free; getcommandlinew; getlasterror; getlasterrortext; getmodulefilename; initializesecuritydescriptor; localfree; lstrlen; malloc; memset; openscmanager; openservice; printf; queryservicestatus; readfile; registereventsource; registerservicectrlhandler; reportevent; reportstatustoscmgr; resetevent; service_ctrl; service_main; servicestart; servicestop; setconsolectrlhandler; setevent; setsecuritydescriptordacl; setservicestatus; sleep; startservicectrldispatcher; strcpy; stricmp; switch; text; waitformultipleobjects; writefile