NSPSetService function

The NSPSetService function registers or deregisters a service instance within a namespace.


int WSAAPI NSPSetService(
  _In_ LPGUID                 lpProviderId,
  _In_ LPWSAQUERYSETW         lpqsRegInfo,
  _In_ WSAESETSERVICEOP       essOperation,
  _In_ DWORD                  dwControlFlags


lpProviderId [in]

A pointer to the GUID of the specific namespace provider in which the service is registered.

lpServiceClassInfo [in]

The service class schema information.

lpqsRegInfo [in]

The property information to be updated upon registration.

essOperation [in]

The type of operation requested.

This parameter can be one of the values from the WSAESETSERVICEOP enumeration type defined in the Winsock2.h header file.


Register the service. For the Service Advertising Protocol (SAP) namespace used within a NetWare environment, this means sending a periodic broadcast. This is an NOP for the Domain Name System (DNS) namespace. For persistent data stores this means updating the address information.


Deregister the service. For the SAP namespace, this means stop sending the periodic broadcast. This is a NOP for the DNS namespace. For persistent data stores this means deleting address information.


Delete the service from dynamic name and persistent spaces. For services represented by multiple CSADDR_INFO structures (using the SERVICE_MULTIPLE flag), only the supplied address will be deleted, and this must match exactly the corresponding CSADDR_INFO structure supplied when the service was registered.


dwControlFlags [in]

A set of flags that controls the service operation requested.

The possible values for this parameter are defined in the Winsock2.h header file.


Control the scope of the operation.

When this value is set, the action is only performed on the given address set. A register operation does not invalidate existing addresses and a deregister operation only invalidates the given set of addresses.

When this value is absent, service addresses are managed as a group. A register or deregister invalidates all existing addresses before adding the given address set.


Return value

The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (–1) if the routine fails and it must set the appropriate error code using WSASetLastError.

Error codeMeaning

The calling routine does not have sufficient privileges to install the service.


There is not enough memory available to perform this operation.


One or more parameters were invalid, or missing, for this provider.


The operation is not supported. This error is returned if the namespace provider does not implement this function.


Service is unknown. The service cannot be found in the specified namespace.



The following table lists the available values for essOperation and dwControlFlags.

OperationFlagsService already existsService does not exist
RNRSERVICE_REGISTERNoneOverwrites the object. Uses only addresses specified. Object is REGISTERED.Creates a new object. Uses only addresses specified. Object is REGISTERED.
RNRSERVICE_REGISTERSERVICE_MULTIPLEUpdates object. Adds new addresses to existing set. Object is REGISTERED.Creates a new object. Uses all addresses specified. Object is REGISTERED.
RNRSERVICE_DEREGISTERNoneRemoves all addresses, but does not remove object from namespace. Object is DEREGISTERED. WSASERVICE_NOT_FOUND
RNRSERVICE_DEREGISTERSERVICE_MULTIPLEUpdates object. Removes only addresses that are specified. Only mark object as DEREGISTERED if no addresses are present. Does not remove from the namespace. WSASERVICE_NOT_FOUND
RNRSERVICE_DELETENoneRemoves object from the namespace. WSASERVICE_NOT_FOUND
RNRSERVICE_DELETESERVICE_MULTIPLERemoves only addresses that are specified. Only removes object from the namespace if no addresses remain. WSASERVICE_NOT_FOUND


When the dwControlFlags parameter is set to SERVICE_MULTIPLE, this enables an application to manage its addresses independently. This is useful when the application must manage its protocols individually or when the service resides on more than one computer. For example, when a service uses more than one protocol, one listening socket may abort, but the other sockets remain operational. In this example, the service could deregister the aborted address without affecting the other addresses.

When using SERVICE_MULTIPLE, an application must not let old addresses remain in the object. This can happen if the application aborts without issuing a RNRSERVICE_DEREGISTER request. When a service registers, it should store its addresses. On its next call, the service should explicitly deregister these old addresses before registering new addresses.

Service Properties

The following table lists WSAQUERYSET member names and describes how service property data is represented. Members labeled as (Optional) can be supplied with a null pointer.

WSAQUERYSET member nameService property description
dwSizeSet to the sizeof(WSAQUERYSET). This is a versioning mechanism.
lpszServiceInstanceNameThe referenced string contains the service instance name.
lpServiceClassIdThe GUID that corresponds to this service class.
lpVersionOptional. Supplies the service instance version number.
lpszCommentOptional. An optional comment string.
dwNameSpaceIgnored for this operation.
lpNSProviderIdIgnored for this operation. The provider identifier is contained in the lpProviderId parameter.
lpszContextOptional. The starting point of the query in a hierarchical namespace.
dwNumberOfProtocolsIgnored for this operation.
lpafpProtocolsIgnored for this operation.
pszQueryStringIgnored for this operation.
dwNumberOfCsAddrsThe number of elements in the array of CSADDR_INFO structures referenced by lpcsaBuffer.
lpcsaBufferA pointer to an array of CSADDR_INFO structures that contain the address or addresses that the service is listening on.
dwOutputFlagsIgnored for this operation.
lpBlobOptional. Pointer to a provider-specific entity.


Note  It is acceptable for the iProtocol member of the CSADDR_INFO structure to contain the manifest constant IPROTOCOL_ANY, indicating a wildcard value. The namespace provider should substitute an acceptable value for the given address family and socket type.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]



See also