Popular Post jguinch Posted October 17, 2013 Popular Post Posted October 17, 2013 (edited) Hello. I did create these few functions several months ago. I post here, if it can interest someone. These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code. Quote HISTORY and RELASE NOTES 2013/10/17 @jguinch * creation of this UDF 2016/07/28 @jguinch * added - EnumPrinter() * added - Pause() * added - PrinterExists() * added - PrintTestPage() * added - RenamePrinter() * added - Resume() 2016/08/19 @jguinch * fixed - in _PrintMgr_EnumPrinter() 2016/08/24 @jguinch * fixed - in _PrintMgr_SetDefaultPrinter() 2016/10/24 @Joboy2k * fixed in _PrintMgr_RemovePrinter() 2017/01/31 * added - _PrintMgr_AddLPRPort() * added - _PrintMgr_RemoveLPRPort() 2017/02/04 @jguinch and @Danyfirex * added - _Printmgr_EnumPorts() * added - _Printmgr_PortExists() * added - _Printmgr_PrinterSetDriver() * added - _Printmgr_PrinterSetPort() 2017/02/05 @jguinch * added - _Printmgr_PrinterSetComment() * added - _Printmgr_PrinterShare() 2017/04/09 @Raceraut * fixed in _PrintMgr_AddWindowsPrinterConnection 2020/09/22 @mlipok * changed - little refactor to be compilant with Au3Check 2020/09/24 @jguinch * fixed - issue which @mLipok found thanks to Au3Check - .SpawnInstance _ * fixed - in _PrintMgr_RemoveLPRPort() function header/documentation _AddLocalPrinterPort >> _PrintMgr_AddLPRPort 2020/09/25 @mlipok * added - HISTORY and RELASE NOTES * fixed - in _PrintMgr_RemoveLocalPort() function header/documentation _AddLocalPrinterPort >> _PrintMgr_AddLocalPort * changed - proper functions name _Printmgr_* >> _PrintMgr_* * changed - modified example - fixed for Au3Check compilance and fixed function names 2020/10/04 @jguinch * changed - HISTORY and RELASE NOTES 2020/11/17 @maniootek * added - $PRINTMGR_* constants in _PrintMgr_EnumPrinterProperties, _PrintMgr_EnumPrinterConfiguration, _PrintMgr_EnumPrinterDriver and _PrintMgr_EnumTCPIPPrinterPort 2021/12/20 @jguinch * added - _PrintMgr_CancelPrintJob * added - _PrintMgr_EnumPrintJobs 2022/01/20 @jguinch * fixed - functions using a printerName parameter didn't work when the specified value was containing backslashes (ex : \\printserver\printers*) Here is the list of the available functions : _PrintMgr_AddLocalPort _PrintMgr_AddLPRPort _PrintMgr_AddPrinter _PrintMgr_AddPrinterDriver _PrintMgr_AddTCPIPPrinterPort _PrintMgr_AddWindowsPrinterConnection _PrintMgr_CancelAllJobs _PrintMgr_CancelPrintJob _PrintMgr_EnumPorts _PrintMgr_EnumPrinter _PrintMgr_EnumPrinterConfiguration _PrintMgr_EnumPrinterDriver _PrintMgr_EnumPrinterProperties _PrintMgr_EnumPrintJobs _PrintMgr_EnumTCPIPPrinterPort _PrintMgr_Pause _PrintMgr_PortExists _PrintMgr_PrinterExists _PrintMgr_PrinterSetComment _PrintMgr_PrinterSetDriver _PrintMgr_PrinterSetPort _PrintMgr_PrinterShare _PrintMgr_PrintTestPage _PrintMgr_RemoveLocalPort _PrintMgr_RemoveLPRPort _PrintMgr_RemovePrinter _PrintMgr_RemovePrinterDriver _PrintMgr_RemoveTCPIPPrinterPort _PrintMgr_RenamePrinter _PrintMgr_Resume _PrintMgr_SetDefaultPrinter And some examples : expandcollapse popup#include <Array.au3> #include "PrintMgr.au3" _Example() Func _Example() ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @ScriptDir & "\Samsung5010", @ScriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers Local $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration Local $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers Local $aDriverList = _PrintMgr_EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _PrintMgr_AddLocalPort("c:\temp\output.pcl") ; Remove the local port _PrintMgr_RemoveLocalPort("c:\temp\output.pcl") ; Enum a print job Local $aJobList = _PrintMgr_EnumPrintJobs() _ArrayDisplay($aJobList) EndFunc ;==>_Example Download link : PrintMgr_Example.au3 PrintMgr.au3 Edited September 26, 2022 by jguinch changed - add some functions ioa747, Subz, tarretarretarre and 13 others 13 3 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
UEZ Posted October 17, 2013 Posted October 17, 2013 Thanks for sharing. Might be useful someday.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
czyt Posted October 18, 2013 Posted October 18, 2013 Thanks,guy!It's useful for me! 董小姐,你微笑的时候很美,就像安河桥下,清澈的水...
Vincor Posted October 22, 2013 Posted October 22, 2013 Can be very useful here too. Once in a while I try to automate something with print queues and ports. I will have it a go in a few days. Thanks jguinch
benched42 Posted April 2, 2014 Posted April 2, 2014 I just came across this UDF and it looks very promising. I'd like to have some documentation on it. For instance, when adding a printer to a computer and I know the driver is not present on the machine, do I use the _AddPrinter or do I use the _AddPrinterDriver followed by the _AddPrinter? Do I need to install the driver first? If so, why is the final parameter only limited to the OS options of Win9x, Win351, NT40 and Win2k? I'm trying to automate adding printers in various locations that do not have servers. All the clients are 64-bit Windows 7 and all printers will be direct TCP/IP port printing to a Canon imageRUNNER (various models). Who lied and told you life would EVER be fair?
jguinch Posted April 3, 2014 Author Posted April 3, 2014 Thank you for your interest. Yes, you must install the driver first (with _AddPrinterDriver). The default value for $sVersion parameter is 3 : it seems Windows 2000 and upper (in your case, I think). You will rarely have to install an old driver on a recent System... So you can use the default value. For the $sDriverPlatform value, the values can be Windows NT x86 or Windows x64. (depending of the type of driver that you want to install). Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Biatu Posted May 25, 2014 Posted May 25, 2014 I made a script to get a list of all printers then remove them all. which works for the most part, but some printers are not removed and get greyed out with a yellow triangle on their icon. the property page is blank. What is what? What is what.
jguinch Posted May 25, 2014 Author Posted May 25, 2014 Biatu : what type are printers that have not been removed ? Shared ? In _RemovePrinter, you must use serverprinterShare for shared printers. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Biatu Posted June 19, 2014 Posted June 19, 2014 (edited) Biatu : what type are printers that have not been removed ? Shared ? In _RemovePrinter, you must use serverprinterShare for shared printers. Nope, they are not shared, or network printers. they are connected via USB port. I test various printers, and the printer list gets pretty full so I run the script. The issue used to be printer jobs from other users, so i made a func to remove all jobs from all printers. Then another dell status service was locking some printers (afaik) so i stop the service. that didnt work completely,so now I restart the spooler service, which remove most. all except for the "Dell 5330 Mono Laser MFP" The env is win7 enterprise x64. Edited June 19, 2014 by Biatu What is what? What is what.
Biatu Posted June 27, 2014 Posted June 27, 2014 _AddPrinter is not working either, i keep getting error dialog... Error Number: -2147352567 WinDescription: Exception occurred. Description: Generic Failure Source: $WbemObjectEx #Include <Printers.au3> $Name="PrintNet.1" $Driver="Dell 2335dn MFP,3,Windows x64" $File="C:\Test1.pcl";@ScriptDir&"\"&$Name&".pcl" _AddPrinter($Name,$Driver,"C:\Test1.pcl") Thanks What is what? What is what.
glakra Posted June 27, 2014 Posted June 27, 2014 Hello Guys, I am new to autoit. I want to run a program called PrinterInfo.exe, search for the the specific word " STATUS_PAPEROUT", if found then send email to desired recipient. So far I have only able to run program, take a window capture save the window capture and then email the window capture to the recipient. But this is not what i want. I have read posts which suggest that I should use WinGetText to retrieve the word, however I have still no idea as to how to search for the specific word " STATUS_PAPEROUT" and if present then send email. Please help
Biatu Posted June 27, 2014 Posted June 27, 2014 (edited) I use this to determine the printer type: http://<Printer IP>:5200/Printer.xml then i use the printer's network interface for everything else. Currently i am doing research with PCL, SNMP, etc. Edited June 27, 2014 by Biatu What is what? What is what.
jguinch Posted June 27, 2014 Author Posted June 27, 2014 Biatu, you have to install the driver before installing the printer : it could be done with _AddPrinterDriver (look at the example above). Next, you have to know the port on which you want to install the printer (if needed, create a network port with _AddTCPIPPrinterPort. And finally, you can add the printer... I just downlod the Dell 2335dn MFP driver, so the installation can be done like this : #Include "printers.au3" Local $sPrinterName = "My Dell 2335dn Printer" Local $sDriverName = "Dell 2335dn MFP" Local $sPortIP = "192.168.1.250" Local $sPortName = "IP_192.168.1.250" Local $iPortnumber = 9100 _AddPrinterDriver($sDriverName, "Windows x64", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\sdf1m.INF") _AddTCPIPPrinterPort($sPortName, $sPortIP, $iPortnumber) _AddPrinter($sPrinterName, $sDriverName, $sPortName) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
jguinch Posted June 27, 2014 Author Posted June 27, 2014 glakra, your question is not about this UDF. Please open a new post in the General Help and Support section. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Biatu Posted June 27, 2014 Posted June 27, 2014 Thank you jguinch, will check out func on monday. What is what? What is what.
Biatu Posted June 30, 2014 Posted June 30, 2014 If I remove a printer using your func will I still need to remove port, or is that auto? Thanks What is what? What is what.
jguinch Posted June 30, 2014 Author Posted June 30, 2014 _RemovePrinter does not remove the port. You must do it after. Same thing for the driver. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Biatu Posted July 2, 2014 Posted July 2, 2014 _RemovePrinter does not remove the port. You must do it after. Same thing for the driver. Tried that, gives error. So i left it out, and the port does not show up on ports list when new printer is added or on the existing ones. So i assume that it's removed automatically What is what? What is what.
ViciousXUSMC Posted April 6, 2015 Posted April 6, 2015 Hmm, is this a global (all users) add/delete of local (current profile)? Speaking exclusively of printserver printers that normally only add per user, unlike local printesr that default to all users.
jguinch Posted April 6, 2015 Author Posted April 6, 2015 _AddWindowsPrinterConnection and _SetDefaultPrinter work for the current profile (the user who runs the script). _AddPrinter adds a local or TCP printer for all users Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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