note 73042 added to function.printer-list

From: Date: Wed, 07 Feb 2007 07:14:27 +0000
Subject: note 73042 added to function.printer-list
Groups: php.notes 
Request: Send a blank email to php-notes+get-123033@lists.php.net to get a copy of this message
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"]; } } } } ---- Server IP: 64.71.164.2 Probable Submitter: 141.154.123.46 ---- Manual Page -- http://www.php.net/manual/en/function.printer-list.php Edit -- https://master.php.net/note/edit/73042 Del: integrated -- https://master.php.net/note/delete/73042/integrated Del: useless -- https://master.php.net/note/delete/73042/useless Del: bad code -- https://master.php.net/note/delete/73042/bad+code Del: spam -- https://master.php.net/note/delete/73042/spam Del: non-english -- https://master.php.net/note/delete/73042/non-english Del: in docs -- https://master.php.net/note/delete/73042/in+docs Del: other reasons-- https://master.php.net/note/delete/73042 Reject -- https://master.php.net/note/reject/73042 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123033) next »