The AddPrinter function adds a printer to the list of supported printers for a specified server.
- pName [in]
A pointer to a null-terminated string that specifies the name of the server on which the printer should be installed. If this string is NULL, the printer is installed locally.
- Level [in]
The version of the structure to which pPrinter points. This value must be 2.
- pPrinter [in]
A pointer to a PRINTER_INFO_2 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.
If the function succeeds, the return value is a handle (not thread safe) to a new printer object. When you are finished with the handle, pass it to the ClosePrinter function to close it.
If the function fails, the return value is NULL.
Do not call this method in DllMain.
The caller must have the SeLoadDriverPrivilege.
The returned handle is not thread safe. If callers need to use it concurrently on multiple threads, they must provide custom synchronization access to the printer handle using the Synchronization Functions. To avoid writing custom code the application can open a printer handle on each thread, as needed.
The following are the members of the PRINTER_INFO_2 structure that can be set before the AddPrinter function is called:
If pSecurityDescriptor is NULL, the system assigns a default security descriptor to the printer. The default security descriptor has the following permissions.
|Administrators and Power Users||Full control on the print queue. This means members of these groups can print, manage the queue (can delete the queue, change any setting of the queue, including the security descriptor), and manage the print jobs of all users (delete, pause, resume, restart jobs).|
Note that Power Users do not exist before Windows XP Professional.
|Creator/Owner||Can manage own jobs. This means that user who submit jobs can manage (delete, pause, resume, restart) their own jobs.|
|Everyone||Execute and standard read control. This means that members of the everyone group can print and read properties of the print queue.|
After an application creates a printer object with the AddPrinter function, it must use the PrinterProperties 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 is not deleted, and the AddPrinter creation parameters are used to change the existing printer settings (as if the application had used the SetPrinter function).
Use the EnumPrintProcessors function to enumerate the set of print processors installed on a server. Use the EnumPrintProcessorDatatypes function to enumerate the set of data types that a print processor supports. Use the EnumPorts function to enumerate the set of available ports. Use the EnumPrinterDrivers function to enumerate the installed printer drivers.
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.
If the DrvPrinterEvent function is passed the PRINTER_EVENT_FLAG_NO_UI flag, the driver should not use a UI call during DrvPrinterEvent. To do UI-related jobs, the installer should either use the VendorSetup entry in the printer's .inf file or, for Plug and Play devices, the installer can use a device-specific co-installer. For more information about VendorSetup, see the Microsoft Windows Driver Development Kit (DDK).
The Internet Connection Firewall (ICF) blocks printer ports by default, but an exception for File and Print Sharing is enabled when you run AddPrinter.
Minimum supported client
Windows 2000 Professional [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Unicode and ANSI names
AddPrinterW (Unicode) and AddPrinterA (ANSI)
- Print Spooler API Functions