The GetPrinter function retrieves information about a specified printer.
BOOL GetPrinter(
HANDLE hPrinter, // handle to printer of interest
DWORD Level, // version of printer info data structure
LPBYTE pPrinter, // pointer to array of bytes that receives
// printer info structure
DWORD cbBuf, // size, in bytes, of the pPrinter buffer
LPDWORD pcbNeeded // pointer to variable with count of bytes
// retrieved (or required)
);
Windows 95: This value can be 1, 2, or 5.
Windows NT: This value can be 1, 2, 3, 4, 5, or 7.
The type of structure is determined by the value of Level.
Level | Structure |
---|---|
1 | A PRINTER_INFO_1 structure containing general printer information. |
2 | A PRINTER_INFO_2 structure containing detailed information about the printer. |
3 | Windows NT: A PRINTER_INFO_3 structure containing the printer's security information. |
4 | Windows NT: A PRINTER_INFO_4 structure containing minimal printer information, including the name of the printer, the name of the server, and whether the printer is remote or local. |
5 | A PRINTER_INFO_5 structure containing printer information such as printer attributes and time-out settings. |
7 | Windows NT 5.0 and later: A PRINTER_INFO_7 structure that indicates whether the printer is published in the directory service. |
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Windows NT: For the PRINTER_INFO_2 and PRINTER_INFO_3 structures that contain a pointer to a security descriptor, the function retrieves only those components of the security descriptor that the caller has permission to read. To retrieve particular security descriptor components, you must specify the necessary access rights when you call the OpenPrinter function to retrieve a handle to the printer. The following table shows the access rights required to read the various security descriptor components.
Access Right | Security Descriptor Component |
---|---|
READ_CONTROL | Owner Primary group Discretionary access-control list (DACL) |
ACCESS_SYSTEM_SECURITY | System access-control list (SACL) |
Windows NT 5.0 and later: You can use level 7 with the PRINTER_INFO_7 structure to determine whether the printer is published in the directory service. If the printer is published, the dwAction member of PRINTER_INFO_7 is set to DSPRINT_PUBLISH and the pszObjectGUID member contains the GUID of the directory services print queue object associated with the printer. If the printer is not published, dwAction is set to DSPRINT_UNPUBLISH.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winspool.h.
Import Library: Use winspool.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
Printing and Print Spooler Overview, Printing and Print Spooler Functions, AbortPrinter, AddPrinter, ClosePrinter, DeletePrinter, EnumPrinters, PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, PRINTER_INFO_5, PRINTER_INFO_7, OpenPrinter, SetPrinter