ekotek Posted January 27, 2010 Posted January 27, 2010 Hey all, Does anyone know of a way to retrieve a listing of all the print queues(nodes) that are set up on a given print server? Basically, I have an app that allows for the entering of a print queue name. What I want to do is verify that print queue actually exists on the print server provided.... Thanks for any help....
water Posted January 27, 2010 Posted January 27, 2010 (edited) You could use WMI. The following code was generated by Sciptomatic. You have to change the select statement (SELECT * FROM Win32_Printer where Servername='\\\\Printserver') to get what you want but I think it can give you an idea.expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Attributes: " & $objItem.Attributes & @CRLF $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $strAvailableJobSheets = $objItem.AvailableJobSheets(0) $Output = $Output & "AvailableJobSheets: " & $strAvailableJobSheets & @CRLF $Output = $Output & "AveragePagesPerMinute: " & $objItem.AveragePagesPerMinute & @CRLF $strCapabilities = $objItem.Capabilities(0) $Output = $Output & "Capabilities: " & $strCapabilities & @CRLF $strCapabilityDescriptions = $objItem.CapabilityDescriptions(0) $Output = $Output & "CapabilityDescriptions: " & $strCapabilityDescriptions & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $strCharSetsSupported = $objItem.CharSetsSupported(0) $Output = $Output & "CharSetsSupported: " & $strCharSetsSupported & @CRLF $Output = $Output & "Comment: " & $objItem.Comment & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $strCurrentCapabilities = $objItem.CurrentCapabilities(0) $Output = $Output & "CurrentCapabilities: " & $strCurrentCapabilities & @CRLF $Output = $Output & "CurrentCharSet: " & $objItem.CurrentCharSet & @CRLF $Output = $Output & "CurrentLanguage: " & $objItem.CurrentLanguage & @CRLF $Output = $Output & "CurrentMimeType: " & $objItem.CurrentMimeType & @CRLF $Output = $Output & "CurrentNaturalLanguage: " & $objItem.CurrentNaturalLanguage & @CRLF $Output = $Output & "CurrentPaperType: " & $objItem.CurrentPaperType & @CRLF $Output = $Output & "Default: " & $objItem.Default & @CRLF $strDefaultCapabilities = $objItem.DefaultCapabilities(0) $Output = $Output & "DefaultCapabilities: " & $strDefaultCapabilities & @CRLF $Output = $Output & "DefaultCopies: " & $objItem.DefaultCopies & @CRLF $Output = $Output & "DefaultLanguage: " & $objItem.DefaultLanguage & @CRLF $Output = $Output & "DefaultMimeType: " & $objItem.DefaultMimeType & @CRLF $Output = $Output & "DefaultNumberUp: " & $objItem.DefaultNumberUp & @CRLF $Output = $Output & "DefaultPaperType: " & $objItem.DefaultPaperType & @CRLF $Output = $Output & "DefaultPriority: " & $objItem.DefaultPriority & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DetectedErrorState: " & $objItem.DetectedErrorState & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "Direct: " & $objItem.Direct & @CRLF $Output = $Output & "DoCompleteFirst: " & $objItem.DoCompleteFirst & @CRLF $Output = $Output & "DriverName: " & $objItem.DriverName & @CRLF $Output = $Output & "EnableBIDI: " & $objItem.EnableBIDI & @CRLF $Output = $Output & "EnableDevQueryPrint: " & $objItem.EnableDevQueryPrint & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $strErrorInformation = $objItem.ErrorInformation(0) $Output = $Output & "ErrorInformation: " & $strErrorInformation & @CRLF $Output = $Output & "ExtendedDetectedErrorState: " & $objItem.ExtendedDetectedErrorState & @CRLF $Output = $Output & "ExtendedPrinterStatus: " & $objItem.ExtendedPrinterStatus & @CRLF $Output = $Output & "Hidden: " & $objItem.Hidden & @CRLF $Output = $Output & "HorizontalResolution: " & $objItem.HorizontalResolution & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "JobCountSinceLastReset: " & $objItem.JobCountSinceLastReset & @CRLF $Output = $Output & "KeepPrintedJobs: " & $objItem.KeepPrintedJobs & @CRLF $strLanguagesSupported = $objItem.LanguagesSupported(0) $Output = $Output & "LanguagesSupported: " & $strLanguagesSupported & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "Local: " & $objItem.Local & @CRLF $Output = $Output & "Location: " & $objItem.Location & @CRLF $Output = $Output & "MarkingTechnology: " & $objItem.MarkingTechnology & @CRLF $Output = $Output & "MaxCopies: " & $objItem.MaxCopies & @CRLF $Output = $Output & "MaxNumberUp: " & $objItem.MaxNumberUp & @CRLF $Output = $Output & "MaxSizeSupported: " & $objItem.MaxSizeSupported & @CRLF $strMimeTypesSupported = $objItem.MimeTypesSupported(0) $Output = $Output & "MimeTypesSupported: " & $strMimeTypesSupported & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $strNaturalLanguagesSupported = $objItem.NaturalLanguagesSupported(0) $Output = $Output & "NaturalLanguagesSupported: " & $strNaturalLanguagesSupported & @CRLF $Output = $Output & "Network: " & $objItem.Network & @CRLF $strPaperSizesSupported = $objItem.PaperSizesSupported(0) $Output = $Output & "PaperSizesSupported: " & $strPaperSizesSupported & @CRLF $strPaperTypesAvailable = $objItem.PaperTypesAvailable(0) $Output = $Output & "PaperTypesAvailable: " & $strPaperTypesAvailable & @CRLF $Output = $Output & "Parameters: " & $objItem.Parameters & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $Output = $Output & "PortName: " & $objItem.PortName & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $strPrinterPaperNames = $objItem.PrinterPaperNames(0) $Output = $Output & "PrinterPaperNames: " & $strPrinterPaperNames & @CRLF $Output = $Output & "PrinterState: " & $objItem.PrinterState & @CRLF $Output = $Output & "PrinterStatus: " & $objItem.PrinterStatus & @CRLF $Output = $Output & "PrintJobDataType: " & $objItem.PrintJobDataType & @CRLF $Output = $Output & "PrintProcessor: " & $objItem.PrintProcessor & @CRLF $Output = $Output & "Priority: " & $objItem.Priority & @CRLF $Output = $Output & "Published: " & $objItem.Published & @CRLF $Output = $Output & "Queued: " & $objItem.Queued & @CRLF $Output = $Output & "RawOnly: " & $objItem.RawOnly & @CRLF $Output = $Output & "SeparatorFile: " & $objItem.SeparatorFile & @CRLF $Output = $Output & "ServerName: " & $objItem.ServerName & @CRLF $Output = $Output & "Shared: " & $objItem.Shared & @CRLF $Output = $Output & "ShareName: " & $objItem.ShareName & @CRLF $Output = $Output & "SpoolEnabled: " & $objItem.SpoolEnabled & @CRLF $Output = $Output & "StartTime: " & WMIDateStringToDate($objItem.StartTime) & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF $Output = $Output & "TimeOfLastReset: " & WMIDateStringToDate($objItem.TimeOfLastReset) & @CRLF $Output = $Output & "UntilTime: " & WMIDateStringToDate($objItem.UntilTime) & @CRLF $Output = $Output & "VerticalResolution: " & $objItem.VerticalResolution & @CRLF $Output = $Output & "WorkOffline: " & $objItem.WorkOffline & @CRLF Next ConsoleWrite($Output) FileWrite(@TempDir & "\Win32_Printer.TXT", $Output ) Run(@Comspec & " /c start " & @TempDir & "\Win32_Printer.TXT" ) Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Printer" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Edited January 27, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ekotek Posted January 27, 2010 Author Posted January 27, 2010 Hmmm...I didn't even think of that -- but, it appears that WMI is locked down on the print server -- won't allow me to read from it.. Verified by trying to just use ScriptOMatic to retrieve some WMI info from the server, and it was disallowed... Any other ideas? Please?
water Posted January 27, 2010 Posted January 27, 2010 If the printers/queues are published to the Active Directory then you can query the AD.Please try the following VB code. If it works then it can be done in AutoIt as well. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ekotek Posted January 27, 2010 Author Posted January 27, 2010 Thanks...yeah, they're all published in AD -- the code is working very well...do you have more information on how to translate to AutoIT?
water Posted January 27, 2010 Posted January 27, 2010 (edited) Thanks...yeah, they're all published in AD -- the code is working very well...do you have more information on how to translate to AutoIT?Not yet. I'm working on a UDF for Active Directory (see the signature of this post). But at the moment it doesn't include printer/printer queue handling.How fast do you need this function?I would like to include it into my AD UDF. Edited January 27, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ekotek Posted January 27, 2010 Author Posted January 27, 2010 That'd be sweet to get it into your UDF -- the sooner, the better, I guess...
water Posted January 27, 2010 Posted January 27, 2010 (edited) I hope to have a test version in the next few days.Download the AD UDF (link can be found in my signature) and try this script:#include <AD.au3> _AD_Open() $aPrinter = _AD_ListPrinter() _ArrayDisplay($aPrinter) _AD_Close() Func _AD_ListPrinter() Local $oAD_Command = ObjCreate("ADODB.Command") $oAD_Command.ActiveConnection = $oAD_Connection $oAD_Command.Properties("Page Size") = 1000 $oAD_Command.Properties("Searchscope") = 2 $oAD_Command.CommandText = "Select printerName, serverName from 'LDAP://" & $sAD_HostServer & "/" & $sAD_DNSDomain & "' WHERE objectClass='printQueue'" Local $oAD_RecordSet = $oAD_Command.Execute Local $aAD_PrinterList[$oAD_RecordSet.RecordCount + 1][2] $oAD_RecordSet.MoveFirst Do $aAD_PrinterList[0][0] += 1 $aAD_PrinterList[$aAD_PrinterList[0][0]][0] = $oAD_RecordSet.Fields("printerName" ).Value $aAD_PrinterList[$aAD_PrinterList[0][0]][1] = $oAD_RecordSet.Fields("serverName" ).Value $oAD_RecordSet.MoveNext Until $oAD_RecordSet.EOF $oAD_RecordSet.Close Return $aAD_PrinterList EndFunc Edited January 27, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ekotek Posted January 27, 2010 Author Posted January 27, 2010 (edited) Here's what I came up with, short and sweet -- working for my needs: Const $ADS_SCOPE_SUBTREE = 2 $objConnection = ObjCreate("ADODB.Connection") $objCommand = ObjCreate("ADODB.Command") $objConnection.provider = "ADsDSOObject" $objConnection.Open = "Active Directory Provider" $objCommand.ActiveConnection = $objConnection $objCommand.CommandText = "Select printerName, serverName from " _ & "'LDAP://DC=wfsi,DC=priv' where objectClass='printQueue'" $objCommand.Properties("Page Size") = 1000 $objCommand.Properties("SearchScope") = $ADS_SCOPE_SUBTREE $objRecordSet = $objCommand.execute $objRecordSet.MoveFirst Do If $objRecordSet.Fields("printerName").Value <> "" And $objRecordSet.Fields("serverName").Value <> "" Then MsgBox(0, "PrinterQueue", "Print Queue Name: " & "\\" & $objRecordSet.Fields("serverName").Value & "\" & $objRecordSet.Fields("printerName").Value) EndIf $objRecordSet.MoveNext Until $objRecordSet.EOF By the way -- can't thank you enough for the quick response and excellent information!! Edited January 27, 2010 by ekotek
water Posted January 27, 2010 Posted January 27, 2010 Glad to be of service. I will incorporate this function into my AD UDF. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ekotek Posted January 27, 2010 Author Posted January 27, 2010 I hope to have a test version in the next few days. Download the AD UDF (link can be found in my signature) and try this script: #include <AD.au3> _AD_Open() $aPrinter = _AD_ListPrinter() _ArrayDisplay($aPrinter) _AD_Close() Func _AD_ListPrinter() Local $oAD_Command = ObjCreate("ADODB.Command") $oAD_Command.ActiveConnection = $oAD_Connection $oAD_Command.Properties("Page Size") = 1000 $oAD_Command.Properties("Searchscope") = 2 $oAD_Command.CommandText = "Select printerName, serverName from 'LDAP://" & $sAD_HostServer & "/" & $sAD_DNSDomain & "' WHERE objectClass='printQueue'" Local $oAD_RecordSet = $oAD_Command.Execute Local $aAD_PrinterList[$oAD_RecordSet.RecordCount + 1][2] $oAD_RecordSet.MoveFirst Do $aAD_PrinterList[0][0] += 1 $aAD_PrinterList[$aAD_PrinterList[0][0]][0] = $oAD_RecordSet.Fields("printerName" ).Value $aAD_PrinterList[$aAD_PrinterList[0][0]][1] = $oAD_RecordSet.Fields("serverName" ).Value $oAD_RecordSet.MoveNext Until $oAD_RecordSet.EOF $oAD_RecordSet.Close Return $aAD_PrinterList EndFunc AWESOME! I will try that as well....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now