Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Script, under a tight timeline, please help!

Status
Not open for further replies.
Mar 11, 2012
4
US
Hey All,

I'm in a bit of a bind with a project for work and could use some assistance. I have almost all of the hta code complete. Long story short our users will use this hta to install printers on a local Win7 machine before connecting to a Citrix session which will redirect that printer.
I am using the below code to pull back the serverName, printerName, and location just fine, where I am struggling is pulling back the Comment or Description field depending on how your looking at it.
If I add comment to the "objCommand.CommandText" it comes back blank.
If I add comment to the "objCommand.CommandText" it comes back blank.
If I add description to the "objCommand.CommandText" it throws an error, the data is invalid
If I add Description to the "objCommand.CommandText" it throws an error, the data is invalid

I know there is data in this property, DSQuery will return the desired results but is slower and messier and I'd prefer not to use it if at all possible.

Code:
' List All Published Printers

c = 0

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, location, Comment from " _     
    & " 'LDAP://DC=firm,DC=saulewing,DC=net'  where objectClass='printQueue'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst



Do Until objRecordSet.EOF
	If c <= 5 Then
		WScript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
    	WScript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
    	WScript.Echo "Printer Location: " & objRecordSet.Fields("location").Value
    	WScript.Echo "Printer OTHER: " & objRecordSet.Fields("Comment").Value
    	objRecordSet.MoveNext
    	c = c + 1
    Else
    	WScript.Quit 8888
    End If
Loop
 
Did you try looking at the object with ADSIEdit to see what the proper filed name is?

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top