note 73042 deleted from function.printer-list by sobak
| From: | sobak@php.net | Date: | Thu, 24 Nov 2016 20:31:42 +0000 |
| Subject: | note 73042 deleted from function.printer-list by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207578@lists.php.net to get a copy of this message | ||
Note Submitter: ewilde aht bsmdevelopment dawt com
----
First, before you do anything, make sure you have a copy of php_printer.dll that is dated later than
the first of February, 2007 because there were several parameter handling bugs that were fixed just
prior to that date.
Also, beware that the Windows function EnumPrinters often does not return all of the networked
printers until someone on the Web server uses the file manager to look at the networked printers,
first. I'm presuming this causes the server to contact the domain controller for the browse
list, which is then used to enumerate the printers. It does not appear that EnumPrinters will do
this on its own, although some of the other values for flags may cause it to do so.
Having said all that, the following code should show you both local and networked printers:
if (function_exists("printer_list"))
{
$PrintCurr = 0;
// Get the local printers.
$PrintDests = printer_list(PRINTER_ENUM_LOCAL);
if (isset($PrintDests))
foreach ($PrintDests as $PrintDest)
$PrinterList[$PrintCurr++] = $PrintDest["NAME"];
// We should be able to enumerate the remote printers too. Let's have a
// shot at it.
//
// Start by looking for the remote printers tree.
$PrintDoms = printer_list(PRINTER_ENUM_NAME); $PrintTree = "";
if (isset($PrintDoms))
foreach ($PrintDoms as $PrintDomain)
{
if (preg_match("/Remote/i", $PrintDomain["NAME"]))
{ $PrintTree = $PrintDomain["NAME"]; break; }
}
// If we found a remote printers tree, we need to enumerate all of the
// domains/workgroups/nodes within the tree and all the printers attached
// to those nodes.
if ($PrintTree != "")
{
// Enumerate all of the domains.
$PrintDoms = printer_list(PRINTER_ENUM_NAME, $PrintTree);
if (isset($PrintDoms))
foreach ($PrintDoms as $PrintDomain)
{
// Enumerate all of the nodes within the domain.
$PrintNodes = printer_list(PRINTER_ENUM_NAME, $PrintDomain["NAME"]);
if (isset($PrintNodes))
foreach ($PrintNodes as $PrintNode)
{
// Enumerate all of the printers within the node.
$PrintDests = printer_list(PRINTER_ENUM_NAME,
$PrintNode["NAME"]);
if (isset($PrintDests))
foreach ($PrintDests as $PrintDest)
$PrinterList[$PrintCurr++] = $PrintDest["NAME"];
}
}
}
}