Searching for Specific Printers in a Domain

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

In addition to enumerating all the printers in a domain, you can search for specific printers. To do this, you simply search for printers that have one or more of the attributes of the printQueue object in Active Directory.

For example, to find all the color printers in the domain, you would search for all printers for which the printsColor attribute is True. To find printers that support stapling, you would search for all printers for which the printStaplingSupported attribute is True.

The printQueue object attributes are shown in Table 13.9.

Table 13.9   Attributes for the printQueue Object

AttributeFriendly NameDescription
cnDirectory Service NameName of the printer as viewed in Active Directory Users and Computers.
uNCNameNetwork NameUNC path of the printer. This attribute is populated by the print spooler when the printQueue object is created.
assetNumberAsset NumberAsset number assigned to the printer. This attribute can be configured by using ADSI.
contactNameContactName of the person to contact regarding the printer. This attribute can be configured by using ADSI.
descriptionCommentDescription of the printer. This is derived from the printer object at the time the printQueue object is created.
driverNameModelModel of the printer. This is derived from the printer driver at the time the printQueue object is created.
locationLocationPhysical location of the printer. This attribute can be configured by using ADSI.
portNamePortName of the port(s) supporting this printer. This attribute is populated by the print spooler when the printQueue object is created.
printBinNamesInput TraysInput tray names. This attribute is populated by the printer driver when the printQueue object is created.
printCollateSupports CollationIndicates whether or not the printer supports collation. This attribute is populated by the printer driver when the printQueue object is created.
printColorSupports Color PrintingIndicates whether or not this is a color device. This attribute is populated by the printer driver when the printQueue object is created.
printDuplexSupportedSupports Double-sided PrintingIndicates whether or not this device can print on both sides of the paper. This attribute is populated by the printer driver when the printQueue object is created.
printerNameNameName of the printer. This attribute is populated by the print object when the printQueue object is created.
printLanguagePrinter LanguagePage description language used by the printer. This attribute is populated by the printer driver when the printQueue object is created.
printMaxResolutionSupportedMaximum ResolutionMaximum resolution (in DPI). This attribute is populated by the printer driver when the printQueue object is created.
printMediaReadyPaper AvailablePaper types loaded in the device at the present time. This attribute is populated by the printer driver when the printQueue object is created.
printMediaSupportedPaper Types SupportedMedia types that the printer supports. This attribute is populated by the printer driver when the printQueue object is created.
printMemoryInstalled MemoryAmount of installed memory. This attribute is populated by the printer driver when the printQueue object is created.
printOwnerOwner NameName of the person or group that owns the printer. This attribute can be configured by using ADSI.
printRateSpeedSpeed of the device. This attribute is populated by the printer driver when the printQueue object is created.
printRateUnitSpeed UnitsUnits that the printer speed is measured in. This attribute is populated by the printer driver when the printQueue object is created.
printPagesPerMinutePages per MinutePrinter speed normalized to pages per minute. This attribute is populated by the printer driver when the printQueue object is created.
printShareNameShare NameShare name of the printer. This attribute is populated by the print object when the printQueue object is created.
printStaplingSupportedSupports StaplingIndicates whether or not the device can staple. This attribute is populated by the printer driver when the printQueue object is created.
serverNameServer NameName of the server supporting the printer. This attribute is populated by the print spooler when the printQueue object is created.
urlWeb Page AddressURL of the printer s Web page. This attribute is populated by the print spooler when the printQueue object is created.
versionNumberObject VersionInternal version number of the printer object. This attribute is populated by the print spooler when the printQueue object is created.

Scripting Steps

Listing 13.26 contains a script that searches for specific printers in Active Directory. To carry out this task, the script must perform the following steps:

  1. Insert an On Error Resume Next statement. This prevents the script from failing if no printers can be found in Active Directory.
  2. Create a constant named ADS_SCOPE_SUBTREE and set the value to 2. This will be used to specify a search that begins in the Active Directory root and proceeds to search all the child containers as well.
  3. Create an instance of the Active Directory connection object (ADODB.Connection).

    The connection object allows you to connect to Active Directory.

  4. Create an instance of the Active Directory command object (ADODB.Command).

    The command object allows you to issue queries and other database commands using the Active Directory connection.

  5. Set the provider property of the connection object to the Active Directory provider (ADsDSOObject). This is the OLE database provider for ADSI.
  6. Set the active connection to the Active Directory connection.
  7. Set the command text for the Active Directory command object to the SQL query that retrieves printer data from fabrikam.com.

    To limit data retrieval to printers with a priority of 2, add the statement "and Priority = 2" to the Where clause. To ensure a quicker search, include only the attributes printerName and serverName in the SQL query.

  8. Specify values for page size, time-out, search scope, and caching.
  9. Run the SQL query.
  10. When the set of printers is returned, use the MoveFirst method to move to the first printer in the recordset.
  11. For each printer in the recordset, echo the printer name and the print server name.

Listing 13.26   Searching for Specific Printers in Active Directory

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 
On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = "SELECT printerName, serverName FROM " _     & "'LDAP://DC=fabrikam,DC=com'  WHERE objectClass='printQueue' AND " _         & " Priority = 2 "  objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF     Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value     Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value     objRecordSet.MoveNext Loop


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net