averlon Posted October 13, 2023 Share Posted October 13, 2023 I have an HP Laserjet printer with duplex. Always after updating windows, the duplex function is disabled. Now I am looking for a autoit-script to set the duplex function what I could run every day at boot. I would like to have some help how to do this! I did not do any autoit on HW! Thanks for hints! Link to comment Share on other sites More sharing options...
mLipok Posted October 13, 2023 Share Posted October 13, 2023 https://learn.microsoft.com/en-us/troubleshoot/windows/win32/modify-printer-settings-setprinter-api or as so far: #include <Array.au3> _Example() Func _Example() Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $colPrinters = $oWMIService.ExecQuery("Select * from Win32_Printer") For $oPrinter In $colPrinters ConsoleWrite($oPrinter.Name & @CRLF) If $oPrinter.Name = "Canon iR-ADV C5250/5255 UFR II" Then Local $capabilities = $oPrinter.Capabilities _ArrayDisplay($capabilities) ConsoleWrite(($capabilities=Null) & @CRLF) ConsoleWrite(VarGetType($capabilities) & @CRLF) EndIf Next EndFunc ;==>_Example Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Nine Posted October 14, 2023 Share Posted October 14, 2023 @averlon take a look of my UDF “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
averlon Posted October 27, 2023 Author Share Posted October 27, 2023 On 10/13/2023 at 11:58 AM, mLipok said: https://learn.microsoft.com/en-us/troubleshoot/windows/win32/modify-printer-settings-setprinter-api or as so far: #include <Array.au3> _Example() Func _Example() Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $colPrinters = $oWMIService.ExecQuery("Select * from Win32_Printer") For $oPrinter In $colPrinters ConsoleWrite($oPrinter.Name & @CRLF) If $oPrinter.Name = "Canon iR-ADV C5250/5255 UFR II" Then Local $capabilities = $oPrinter.Capabilities _ArrayDisplay($capabilities) ConsoleWrite(($capabilities=Null) & @CRLF) ConsoleWrite(VarGetType($capabilities) & @CRLF) EndIf Next EndFunc ;==>_Example What does this UDF tell me? The output is a table with 2 columns, ROW and Col0 including some values. I assume, this shows the raw data what capabilities the printer has. But question is how to translate the figures and how to set the duplex function. I guess, I am not sure, there is nothing in the script on that!? Link to comment Share on other sites More sharing options...
argumentum Posted October 27, 2023 Share Posted October 27, 2023 (edited) 3 hours ago, averlon said: I guess, I am not sure, there is nothing in the script on that!? change _ArrayDisplay() to _ArrayToString() and post the results. That way we ( @mLipok really ) can help you better Edit: reading the code a bit more, I see that you have an HP and he's filtering for a cannon printer ( he may not have your printer. I myself have none ). Do remove the filter and tweak it to have an output that makes sense. Edited October 27, 2023 by argumentum clarify Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
mLipok Posted October 27, 2023 Share Posted October 27, 2023 3 hours ago, argumentum said: That way we ( @mLipok really ) can help you better Rather @Nine in this topic: argumentum 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
averlon Posted November 11, 2023 Author Share Posted November 11, 2023 Hi, O.K. - it took some time to understand the way the UDF has to be used!!!! Anyhow, I don't get it working. #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> #include <Printer_UDF.au3> Opt("MustDeclareVars", True) Example() Func Example() Local $hPrinter = _PRNT_OpenPrinter("HP Color LaserJet CP202X PS Class Driver") Local $tDevMode = _PRNT_GetPrinterInfo($hPrinter, True) ConsoleWrite($tDevMode.Duplex & @CRLF) ConsoleWrite($tDevMode.FormName & @CRLF) ConsoleWrite(_PRNT_IsValidDevmode($tDevMode) & @CRLF) _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, 1, True) _PRNT_ClosePrinter($hPrinter) EndFunc ;==>Example The printer configuration shows still "Duplex = not installed". The "ConsoleWrite($tDevMode.Duplex & @CRLF)" shows "1". By the way: I found a way to configure the printer via Microsoft PowerShell. Set-PrinterProperty -PrinterName "HP Color LaserJet CP202X PS Class Driver" -PropertyName "Config:Duplexer" -Value "Installed" Here the value to be set is "Installed" - and this works! Therefore I tried to modify the UDF Func _PRNT_SetPrinterInfo($hPrinter, $iProp, $iValue, $bGlobal) If Not $hPrinter Or Not BitAND($iProp, $PRINTER_AUTHORIZED_PROPERTIES) Or Not IsBool($bGlobal) Then Return SetError(1) and eliminated (for test purposes) the testing of the $iValue and used _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, "Installed", True) but also with no positive result. Link to comment Share on other sites More sharing options...
averlon Posted November 11, 2023 Author Share Posted November 11, 2023 (edited) I changed the script slightly: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> #include <Printer_UDF.au3> Opt("MustDeclareVars", True) Example() Func Example() Local $hPrinter = _PRNT_OpenPrinter("HP Color LaserJet CP202X PS Class Driver") Local $tDevMode = _PRNT_GetPrinterInfo($hPrinter, False) ConsoleWrite($tDevMode.Duplex & @CRLF) ConsoleWrite($tDevMode.FormName & @CRLF) ConsoleWrite(_PRNT_IsValidDevmode($tDevMode) & @CRLF) Local $aList = _PRNT_EnumJobs($hPrinter) ConsoleWrite(_ArrayToString($aList) & @CRLF) _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, 1, False) Local $tDevMode = _PRNT_GetPrinterInfo($hPrinter, True) ConsoleWrite($tDevMode.Duplex & @CRLF) ConsoleWrite($tDevMode.FormName & @CRLF) ConsoleWrite(_PRNT_IsValidDevmode($tDevMode) & @CRLF) Local $aList = _PRNT_EnumJobs($hPrinter) ConsoleWrite(_ArrayToString($aList) & @CRLF) _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, 1, True) _PRNT_ClosePrinter($hPrinter) EndFunc ;==>Example The console output is: 1 A4 1 0|||||||||| 1 A4 1 0|||||||||| >Exit code: 0 Question: Does "ConsoleWrite($tDevMode.Duplex & @CRLF)" only show, that the device has the option "Duplex", but not, whether it is enabled or not!? Beside all this: _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, "Installed", True) does not bring any error (with the Original UDF), although $iValue is !!not!! and Integer! Where based on my knowledge it shoud bring an error: If Not $hPrinter Or Not IsInt($iValue) Or Not BitAND($iProp, $PRINTER_AUTHORIZED_PROPERTIES) Or Not IsBool($bGlobal) Then Return SetError(1) Edited November 11, 2023 by averlon Link to comment Share on other sites More sharing options...
Nine Posted November 11, 2023 Share Posted November 11, 2023 There is 3 possible values for Duplex : Value Meaning DMDUP_SIMPLEX(1) Normal (nonduplex) printing. DMDUP_HORIZONTAL(3) Short-edge binding, that is, the long edge of the page is horizontal. DMDUP_VERTICAL(2) Long-edge binding, that is, the long edge of the page is vertical. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
averlon Posted November 11, 2023 Author Share Posted November 11, 2023 (edited) unfortunately it still does not work! Befor Script: Script: expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> #include <Printer_UDF.au3> #include <WinAPIGdi.au3> #include <WinAPIDiag.au3> Opt("MustDeclareVars", True) Example() Func Example() ConsoleWrite("--- START ---" & @CRLF) Local $hPrinter = _PRNT_OpenPrinter("HP Color LaserJet CP202X PS Class Driver") Local $tDevMode = _PRNT_GetPrinterInfo($hPrinter, True) ConsoleWrite("Orientation: " & $tDevMode.Orientation & @CRLF) ConsoleWrite("PaperSize: " & $tDevMode.PaperSize & @CRLF) ConsoleWrite("PaperLength: " & $tDevMode.PaperLength & @CRLF) ConsoleWrite("PaperWidth: " & $tDevMode.PaperWidth & @CRLF) ConsoleWrite("Scale: " & $tDevMode.Scale & @CRLF) ConsoleWrite("Copies: " & $tDevMode.Copies & @CRLF) ConsoleWrite("DefaultSource: " & $tDevMode.DefaultSource & @CRLF) ConsoleWrite("PaperWidth: " & $tDevMode.PaperWidth & @CRLF) ConsoleWrite("Color: " & $tDevMode.Color & @CRLF) ConsoleWrite("Duplex: " & $tDevMode.Duplex & @CRLF) ConsoleWrite("YRresolution: " & $tDevMode.YRresolution & @CRLF) ConsoleWrite("TTOption: " & $tDevMode.TTOption & @CRLF) ConsoleWrite("Collate: " & $tDevMode.Collate & @CRLF) ConsoleWrite("FormName: " & $tDevMode.FormName & @CRLF) ConsoleWrite("is valid DevMode: " & _PRNT_IsValidDevmode($tDevMode) & @CRLF) Local $aList = _PRNT_EnumJobs($hPrinter) ConsoleWrite("---aList: " & _ArrayToString($aList) & @CRLF) _PRNT_SetPrinterInfo($hPrinter, $DM_DUPLEX, 2, False) Local $tDevMode = _PRNT_GetPrinterInfo($hPrinter, False) ConsoleWrite("--- after SetPrinterInfo ---" & @CRLF) ConsoleWrite("Duplex: " & $tDevMode.Duplex & @CRLF) _PRNT_ClosePrinter($hPrinter) EndFunc ;==>Example Console Print: --- START --- Orientation: 1 PaperSize: 9 PaperLength: 2970 PaperWidth: 2100 Scale: 100 Copies: 1 DefaultSource: 15 PaperWidth: 2100 Color: 2 Duplex: 1 YRresolution: 0 TTOption: 3 Collate: 1 FormName: A4 is valid DevMode: 1 ---aList: 0|||||||||| --- after SetPrinterInfo --- Duplex: 2 >Exit code: 0 Printer configuration after Script: I have crosschecked the configuration with some application where I wanted to print a page (Word) and open the configuration before printing. Duplx printing is not offered! And by the way: I doubt, there are these options you mentioned. As far as I know, the type of duplex printing can be selected when printing. But what I am looking for is "to enable" duplex printing. So the configuration setting must tell me "Installed". At that configuration setting you don't have the option to select long- or short-page! As I stated above, this PowerShell-Script does the trick - but I don't want to enable PowerShell on my device! Set-PrinterProperty -PrinterName "HP Color LaserJet CP202X PS Class Driver" -PropertyName "Config:Duplexer" -Value "Installed" I have the feeling, we are talking about different type of settings. Edited November 11, 2023 by averlon Link to comment Share on other sites More sharing options...
Nine Posted November 11, 2023 Share Posted November 11, 2023 19 minutes ago, averlon said: I have the feeling, we are talking about different type of settings. No doubt. Spooler will not install your duplex unit. Maybe minic your manual installation with UIAutomation. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
averlon Posted November 12, 2023 Author Share Posted November 12, 2023 O.K. - what I assumed. All work here was for nothing. Anyhow. Since I can set the duplex unit via the printer configuration GUI of Windows, I should be able to do the same via autoit. I will try to find a way! Thanks for support! Link to comment Share on other sites More sharing options...
averlon Posted November 12, 2023 Author Share Posted November 12, 2023 I found a solution. Not the very best, but it seems to work. There is a Microsoft Tool where you can store the printers configuration in a .dat-file. This is what you need to do only once, naturally when the printer settings are according to your needs - duplex: "Installed" - in my case. rundll32.exe printui.dll,PrintUIEntry /Ss /n"<printer name>" /a"<some path to file>\printer_configuration.dat" d You can do this via WINDOWS+R and past the command into the commandline field and ENTER. Now, you have the printer configuration stored in the file specified! Now you can create a autoit script and run the script at "autostart". Run('rundll32.exe printui.dll,PrintUIEntry /Sr /n"<printer name>" /a"<some path to file>\printer_configuration.dat" d') This will restore the configuration to the settings you stored with the commandline shown above. For more information on the printerui see https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/rundll32-printui#related-links So far, I havn't found any way to modify one specific printer property. So the only way is to store and restore the whole configuration! mLipok 1 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