ServiceClosePort (Windows CE 5.0)

Send Feedback

This function closes the specified port listening on the super server.

BOOL ServiceClosePort(HANDLE hService, SOCKADDR* pSockAddr, int cbSockAddr, int iProtocol, BOOL fRemoveFromRegistry);


  • hService
    [in] Handle to the service instance of port to unbind.
  • pSockAddr
    [in] Pointer to the address of the port to stop listening on.
  • cbSockAddr
    [in] Length of pSockAddr.
  • iProtocol
    [in] Protocol of the socket to stop listening on.
  • fRemoveFromRegistry
    [in] TRUE specifies that the registry key in HKEY_LOCAL_MACHINE\Services\ServiceName\Accept associated with this port should be deleted. Doing this causes the port to not be listened on the next time the service is loaded. Setting this value to FALSE means that, if the port information has been persisted to the registry, the next time the service is loaded this address will be listened on by Services.exe's super server.

Return Values

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.


This function provides granular control over which ports will no longer be listened on. The parameters pSockAddr, cbSockAddr, and iProtocol must match a currently open port's settings exactly or this function will fail and SetLastError to ERROR_SERVICE_CANNOT_ACCEPT_CTRL.

To close all sockets that are associated with a particular service, call ServiceUnbindPorts.


OS Versions: Windows CE .NET 4.1 and later.
Header: Service.h.
Link Library: Coredll.lib.

See Also

ServiceUnbindPorts | Services.exe

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.