EnumPorts

BOOL EnumPorts(
    LPTSTR   pName,
    DWORD    Level,
    LPBYTE   pPorts,
    DWORD    cbBuf,
    LPDWORD  pcbNeeded,
    LPDWORD  pcReturned
);
 

A port management function that provides a list of all the ports available for printing on the local machine through your port monitor. The spooler calls all installed monitors in turn to build up a list of all the available ports.

Returns TRUE if the operation is successful.

pName Specifies the name of the machine on which to enumerate the ports. This parameter is set to NULL for the local machine.
Level Specifies the version of the structure to which the pPorts parameter points. This value must be 1 or 2.
pPorts Points to a buffer into which to copy the array of PORT_INFO_1 or PORT_INFO_2 structures that describe all the available ports.
cbBuf Specifies the size of the buffer, in bytes, supplied by the caller and to which the pPorts parameter points.
pcbNeeded Points to a value containing the required buffer size to return all of the port enumeration information (the array of PORT_INFO_1 or PORT_INFO_2 structures). If the cbBuf parameter value specified by the caller is too small, EnumPorts sets GetLastError to ERROR_INSUFFICIENT_BUFFER and the caller can obtain the number of bytes required from the memory location pointed to by pcbNeeded. If the cbBuf parameter value is sufficient to hold all the port enumeration information, then pcbNeeded points to the number of bytes actually used in the buffer.
pcReturned Points to a variable that contains the number of PORT_INFO_1 or PORT_INFO_2 structures returned in the buffer pointed to by the pPorts parameter.

The machine does not need to have a printer defined for this function to work.