Partager via


ServiceClosePort

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

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

Syntax

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

Parameters

  • 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 Value

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

Remarks

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.

Requirements

Header service.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.1 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

ServiceUnbindPorts

Other Resources

Services.exe