ADODB.Connection
(1)
ADODB.Command
(1)
Active Directory
(1)
ObjWMIService.ExecQuery
(1)
ADsDSOObject
(1)
ADODB
(1)
ObjRecordSet.MoveFirst
(1)
ObjRecordSet.MoveNext
(1)

Query printers in 2008 domain using vbscript or WMI

Asked By ABC Webmaster
11-Mar-10 10:01 AM
I have the following code which I use to query published printers in
AD on our domain (2003). We have now setup a 2 way trust with another
domain (2008) which I can browse to with no problems. The problem
occurs when I try and run this script with the remote domain in the
LDAP query returns "Provider: A referral was returned from the
server."


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=DOMAIN,DC=COM' WHERE objectClass='printQueue'"
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


I have also tried it like this using WMI but that just hangs ....

strComputer = "printserver"
Set objWMIService = GetObject("winmgmts:" &
Set colInstalledPrinters = objWMIService.ExecQuery ("SELECT * FROM
Win32_Printer")

For Each objPrinter in colInstalledPrinters
Wscript.Echo "\\" & strComputer & "\" & objPrinter.name
Next

Has anyone managed to query a remote print server to get this info?
Post Question To EggHeadCafe