bscarano Posted February 14, 2017 Share Posted February 14, 2017 Hello Everyone, What I am trying to accomplish is have an array with Values (printer names) and check that against the installed printers using _PrintMGR_PrinterExists. If the printer exists on the system, delete any printer jobs and then delete the printer. I have I'm not sure how to code the array check to the printers installed. #include "PrintMgr.au3" #include <Array.au3> $LblPrnArr[2] = ["DYMO LabelWriter 330","DYMO LabelWriter 330-USB"] For $i = 0 to UBound($LblPrnArr) -1 _ArrayDisplay($LblPrnArr) Local $sSearch = _Printmgr_PrinterExists($LblPrnArr[2]) If _Printmgr_PrinterExists($LblPrnArr[2]) = 1 Then ;If installed printer matches MsgBox(0,"It's here","It's here!") Else ; not installed MsgBox(0,"Negative", "Your code didn't work") EndIf Next Any help is appreciated. Link to comment Share on other sites More sharing options...
water Posted February 14, 2017 Share Posted February 14, 2017 (edited) Should be something like this: #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr[2] = ["DYMO LabelWriter 330","DYMO LabelWriter 330-USB"] Global For $i = 0 to UBound($LblPrnArr) -1 If _Printmgr_PrinterExists($LblPrnArr[$i]) = 1 Then ; If installed printer matches MsgBox(0,"It's here","Printer " & $LblPrnArr[$i] & " found!") Else ; not installed MsgBox(0,"Negative", "Your code didn't work") EndIf Next Edited February 14, 2017 by water bscarano 1 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 Link to comment Share on other sites More sharing options...
bscarano Posted February 14, 2017 Author Share Posted February 14, 2017 Thank You Water! Is there a way to run for each match found? The machine(s) may have multiple instances of the printers running. (Copy 1) (Copy 2) etc. Is there a way to say "for each match. . run this code" Link to comment Share on other sites More sharing options...
jguinch Posted February 14, 2017 Share Posted February 14, 2017 To cancel jobs and remove the printer : #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr[2] = ["DYMO LabelWriter 330","DYMO LabelWriter 330-USB"] For $i = 0 to UBound($LblPrnArr) -1 If _Printmgr_PrinterExists($LblPrnArr[$i]) Then ; If installed printer matches If _PrintMgr_CancelAllJobs($LblPrnArr[$i]) Then _PrintMgr_RemovePrinter($LblPrnArr[$i]) EndIf Else ; not installed MsgBox(0,"Negative", "Printer " & $LblPrnArr[$i] & " not found") EndIf Next bscarano 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
water Posted February 14, 2017 Share Posted February 14, 2017 Could there be printers with unique names like "DYMO LabelWriter 330 (Copy 1)" and "DYMO LabelWriter 330 (Copy 2)" or the same printer name "DYMO LabelWriter 330" multiple times? 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 Link to comment Share on other sites More sharing options...
bscarano Posted February 14, 2017 Author Share Posted February 14, 2017 (edited) Most likely, (Copy 1), (Copy 2) Although, there could be Dymo 330 and a Dymo 330-USB Edited February 14, 2017 by bscarano added additional info Link to comment Share on other sites More sharing options...
water Posted February 14, 2017 Share Posted February 14, 2017 (edited) #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr[2] = ["DYMO LabelWriter 330", "DYMO LabelWriter 330-USB"] Global $aPrinters = _PrintMgr_EnumPrinter() ; Get a list of all printers For $i = 0 To $aPrinters[0] ; Loop through all printers For $j = 0 To UBound($LblPrnArr) - 1 ; Loop through all printer types to check If StringInStr($aPrinters[$i], $LblPrnArr($j)) Then MsgBox(0, "It's here", "Printer " & $aPrinters[0] & " matches " & $LblPrnArr[$j] & "!") Else ; not installed MsgBox(0, "Negative", "Your code didn't work") EndIf Next Next Get a list of all printers and then check for each printer name if it contains (substring) one of the printer types listed in $lblPrnArr. Edited February 14, 2017 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 Link to comment Share on other sites More sharing options...
bscarano Posted February 14, 2017 Author Share Posted February 14, 2017 Hmm, ok, when I try to run, it states (Variable cannot be accessed in this manner)? Link to comment Share on other sites More sharing options...
jguinch Posted February 14, 2017 Share Posted February 14, 2017 (edited) You can search printers by name using a filter with _PrintMgr_EnumPrinter : #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr = ["DYMO LabelWriter 330*", "HP Deskjet 2540*"] For $i = 0 To UBound($LblPrnArr) - 1 ; Loop through all printer types to check $aPrinters = _PrintMgr_EnumPrinter($LblPrnArr[$i]) If Not @error And $aPrinters[0] Then ConsoleWrite("!" & $aPrinters[0] & " printer(s) matching '" & $LblPrnArr[$i] & "' found : " & @CRLF) For $j = 1 To $aPrinters[0] ConsoleWrite(" - " & $aPrinters[$j] & @CRLF) ;~ If _PrintMgr_CancelAllJobs($aPrinters[$j]) Then _PrintMgr_RemovePrinter($aPrinters[$j]) ; <--- Cancel jobs and remove printer Next Else ConsoleWrite("!No printer matches '" & $LblPrnArr[$i] & "'" & @CRLF) EndIf Next Edit : because the printer name is not a sure way, I recommend you to check for the driver name : #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr = ["DYMO LabelWriter 330", "HP Deskjet 2540"] Local $aPrinters = _PrintMgr_EnumPrinterProperties() For $i = 0 To UBound($aPrinters) - 1 $sPrinterName = $aPrinters[$i][53] $sDriverName = $aPrinters[$i][31] For $j = 0 To UBound($LblPrnArr) - 1 If StringInStr($sDriverName, $LblPrnArr[$j]) Then ConsoleWrite("Then printer " & $sPrinterName & " uses the driver " & $LblPrnArr[$j] & @CRLF) ;~ If _PrintMgr_CancelAllJobs($sPrinterName) Then _PrintMgr_RemovePrinter($sPrinterName]) ; <--- Cancel jobs and remove printer EndIf Next Next Edited February 14, 2017 by jguinch spudw2k 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
bscarano Posted February 14, 2017 Author Share Posted February 14, 2017 34 minutes ago, jguinch said: You can search printers by name using a filter with _PrintMgr_EnumPrinter : #include "PrintMgr.au3" #include <Array.au3> Global $LblPrnArr = ["DYMO LabelWriter 330*", "HP Deskjet 2540*"] For $i = 0 To UBound($LblPrnArr) - 1 ; Loop through all printer types to check $aPrinters = _PrintMgr_EnumPrinter($LblPrnArr[$i]) If Not @error And $aPrinters[0] Then ConsoleWrite("!" & $aPrinters[0] & " printer(s) matching '" & $LblPrnArr[$i] & "' found : " & @CRLF) For $j = 1 To $aPrinters[0] ConsoleWrite(" - " & $aPrinters[$j] & @CRLF) ;~ If _PrintMgr_CancelAllJobs($aPrinters[$j]) Then _PrintMgr_RemovePrinter($aPrinters[$j]) ; <--- Cancel jobs and remove printer Next Else ConsoleWrite("!No printer matches '" & $LblPrnArr[$i] & "'" & @CRLF) EndIf Next It worked! Thank You all so much. I was racking my brain trying to figure this out. Link to comment Share on other sites More sharing options...
jguinch Posted February 14, 2017 Share Posted February 14, 2017 Glag to help you. I'm happy to see that some people use my UDF Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
bscarano Posted February 14, 2017 Author Share Posted February 14, 2017 I did not even realize you wrote it. It is awesome!! Thanks for creating! Link to comment Share on other sites More sharing options...
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