AddPrinter  HOFX1L 

The AddPrinter function adds a printer to the list of supported printers for a specified server.

HANDLE AddPrinter(

    LPTSTR pName,

// pointer to server name

    DWORD Level,

// printer info. structure level 

    LPBYTE pPrinter

// pointer to structure

   );

 

 

Parameters

pName

Pointer to a null-terminated string that specifies the name of the server on which the printer s print processor should be installed. If this string is NULL, the print processor is installed locally.

Level

Specifies the version of the structure to which pPrinter points. This value must be 2.

pPrinter

Pointer to a PRINTER_INFO_2X0ETHP structure that contains information about the printer. You must specify non-NULL values for the pPrinterName, pPortName, pDriverName, and pPrintProcessor members of this structure before calling AddPrinter.

 

Return Values

If the function succeeds, the return value is the handle to a new printer object.

If the function fails, the return value is NULL. To get extended error information, call GetLastError11C2VS7.

Remarks

The following list identifies the members of the PRINTER_INFO_2 structure that can be set before the AddPrinter function is called.

Attributes

pPrintProcessor

DefaultPriority

Priority

pComment

pSecurityDescriptor

pDatatype

pSepFile

pDevMode

pShareName

pLocation

StartTime

pParameters

UntilTime

 

The Status, cJobs, and AveragePPM members of the PRINTER_INFO_2 structure are reserved for use by the GetPrinterEK5Z48 function. They must not be set before calling AddPrinter.

If pSecurityDescriptor is NULL, the system assigns a default security descriptor to the printer.

After an application creates a printer object with the AddPrinter function, it must use the PrinterProperties5A7CXRP function to specify the correct settings for the printer driver associated with the printer object.

The AddPrinter function returns an error if a printer object with the same name already exists, unless that object is marked as pending deletion. In that case, the existing printer will not be deleted, and the AddPrinter creation parameters will be used to change the existing printer settings (as if the application had used the SetPrinter function).

Windows NT:The caller of the AddPrinter function must have SERVER_ACCESS_ADMINISTER access to the server on which the printer is to be created. The handle returned by the function will have PRINTER_ALL_ACCESS permission, and can be used to perform administrative operations on the printer.

Windows 95: This access validation is not supported in Windows 95.

Use the EnumPrintProcessors function to enumerate the set of print processors installed on a server. Use the EnumPrintProcessorDatatypes function to enumerate the set of datatypes that a print processor supports.

See Also

ClosePrinter, DeletePrinter, EnumPrintProcessors, EnumPrintProcessorDatatypes, GetPrinter, PRINTER_INFO_2, PrinterProperties, SetPrinter