Jump to content

Recommended Posts

Posted

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!

Posted

 

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted
  On 10/13/2023 at 9: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

 

Expand  

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!?

Posted (edited)
  On 10/27/2023 at 10:26 AM, averlon said:

I guess, I am not sure, there is nothing in the script on that!?

Expand  

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 by argumentum
clarify

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
  On 10/27/2023 at 1:37 PM, argumentum said:

That way we ( @mLipok really :) ) can help you better ;) 

Expand  

Rather @Nine in this topic:

 

 

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted

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.

Posted (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

image.png.7414af03188a50ef9b89ada94e095e13.png

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 by averlon
Posted

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.
Posted (edited)

unfortunately it still does not work!

Befor Script:

image.png.d46f46002fb5456816a0abb2919b4419.png

Script:

#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:

image.png.fbc521cf2701598ac5fe4d6b8cfb403f.png

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 by averlon
Posted
Posted

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!

Posted

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!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...