4 Protocol Examples

The client receives a request from an application such as Services.msc to open the SCM database on the server for reading. After establishing a connection to the server, the client sends an ROpenSCManagerW call with the following values for the parameters.

 lpMachineName = "Name of the Server"
 lpDatabaseName = "ServicesActive"
 dwDesiredAccess = 0x00000001
 lpScHandle = NULL

Upon receiving this request from the client, the server opens the handle to the SCM database with read access, the method returns an error code of 0, and the pointer is set to the opened handle in the lpScHandle parameter of the response.

The client can then use the handle returned in lpScHandle to operate on SCM database. For instance, to query the display name associated with a service, the client sends an RGetServiceDisplayNameW call with the following values for the parameters.

 hSCManager = Handle returned in the lpScHandle parameter of the 
              previous server response.
 lpServiceName = "GenericService\0"
 lpDisplayName = Pointer to buffer that will receive the display name
 lpcchBuffer = Size of the buffer pointed to by the lpDisplayName 
               parameter

Upon receiving this request from the client, the server queries the display name associated with the service "GenericService", the method returns an error code of 0, and then the server fills the display name in the buffer pointed to by the lpDisplayName parameter of the response.

When it is finished operating on the SCM database, the client closes the handle to this database by sending an RCloseServiceHandle with the following values for the parameters.

 hSCObject = Handle returned in the lpScHandle parameter of the server 
             response to the ROpenSCManagerW call.

Upon receiving this request from the client, the server closes the handle to the open SCM database, and the method returns an error code of 0.