Jump to content

Recommended Posts

Posted (edited)

Ok I found the error for the Kiocera, I made a mistake in the driver name... I add a space before "KX".

Edited by SamSam
Posted (edited)

@jguinch I download your UDF from OP and chceck them ... little refactor to be compilant with:

#AutoIt3Wrapper_Run_AU3Check=Y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

There is one problem in:

Func _PrintMgr_AddTCPIPPrinterPort($sPortName, $sPortIP, $sPortNumber)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If Not IsObj($oWMIService) Then Return SetError(1, 0, 0)
    Local $oNewPort = $oWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance _
            If Not IsObj($oNewPort) Then Return SetError(1, 0, 0)
    $oNewPort.Name = $sPortName
    $oNewPort.Protocol = 1
    $oNewPort.HostAddress = $sPortIP
    $oNewPort.PortNumber = $sPortNumber
    $oNewPort.SNMPEnabled = True
    Local $ret = $oNewPort.Put_
    #forceref $ret
    Return 1
EndFunc   ;==>_PrintMgr_AddTCPIPPrinterPort
  Quote

"C:\Users\Szef\Downloads\PrintMgr.au3"(169,4) : error: syntax error
            If
            ^
"C:\Users\Szef\Downloads\PrintMgr.au3"(169,52) : error: Statement cannot be just an expression.
            If Not IsObj($oNewPort) Then Return SetError(1, 0
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Szef\Downloads\PrintMgr.au3"(169,55) : error: Statement cannot be just an expression.
            If Not IsObj($oNewPort) Then Return SetError(1, 0, 0
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Szef\Downloads\PrintMgr.au3"(169,57) : error: Statement cannot be just an expression.
            If Not IsObj($oNewPort) Then Return SetError(1, 0, 0)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Expand  

 

Could you please check it ?

EDIT:
Here are my modifed/refactored/reviewed scripts:

PrintMgr.au3Fetching info... PrintMgr_Example.au3Fetching info...

Edited by mLipok

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

Posted
  On 9/22/2020 at 9:16 AM, mLipok said:

Could you please check it ?

Expand  

Will you be able to look on this ?

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

Posted

New version:

  Quote

#CS
    HISTORY and RELASE NOTES
    2013/10/17-2020/09/21 @jguinch and other..... I @mLipok do not know the story @jguinch must to rewrite it :)

    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

#CE
 

Expand  

@jguinch please check when you will have some spare time.

 

PrintMgr.au3Fetching info... PrintMgr_Example.au3Fetching info...

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

  • 1 month later...
Posted (edited)

Didn't you plan to create global enum values for table index reference of result of functions like _PrintMgr_EnumPrinterConfiguration or _PrintMgr_EnumPrinterProperties ?

Edited by maniootek
Posted (edited)

@maniootek : well, I thought  about it but didn't really know how.

Here is a new version (-see first message- ). Please, give me your advice

PrintMgr.au3Fetching info...

Edited by jguinch
Posted
  On 11/17/2020 at 8:23 PM, jguinch said:

@maniootek : well, I thought  about it but didn't really know how.

Here is a new version. Please, give me your advice : PrintMgr.au3

Expand  

Yes, this is it. Please also note that if you have some constants with value starting from 0 and increase by 1+ you can use Enum instead of declaring each variable.

This piece of code:

Global Const $PRINTMGR_PROPERTY_ATTRIBUTES = 0
Global Const $PRINTMGR_PROPERTY_AVAILABILITY = 1
Global Const $PRINTMGR_PROPERTY_AVAILABLEJOBSHEETS = 2
Global Const $PRINTMGR_PROPERTY_AVERAGEPAGESPERMINUTE = 3

Do the same job as this one:

Global Enum $PRINTMGR_PROPERTY_ATTRIBUTES, $PRINTMGR_PROPERTY_AVAILABILITY, $PRINTMGR_PROPERTY_AVAILABLEJOBSHEETS, $PRINTMGR_PROPERTY_AVERAGEPAGESPERMINUTE

But anyway, the first version even looks better.

Posted (edited)

yes, I know, but I find it more readable like it. 🙂

... and "some constants with value starting from 0" => it can start with another value (ex Global Const $val = 50, $val2 ...

@maniootek : the downloaded link is updated. Thanks for your advice.
Edit : I added your name in the HISTORY 😉

Edited by jguinch
Posted

image.thumb.png.668df5ae54fd67ec22c27e9864ade735.png

After running the script, the printer is not removed.
Don't know why it doesn't remove the printer?
And windows has shown that the printer driver is unavailable!

Regards,
 

Posted

@jguinch _PrintMgr_RemovePrinter returns 1 and @Error 0 

But the printer has been removed in the Printer Management.

image.png.ab4d08c2267809b42160be0daecd7ff0.png

I added a line of code to the UDF and the printer is completely removed!

image.thumb.png.08f97f28957255d641c61d49ee3905a8.png

 

Regards,
 

Posted (edited)

I tweaked the function to get more options!

Global $_PrintMgr_ObjError=0, $_ObjError = ObjEvent("AutoIt.Error", "_ObjError")   ; Initialize a COM error handler
; This is custom defined error handler
Func _ObjError()
    $_PrintMgr_ObjError=1
    Return SetError(1, 0, 0)
EndFunc   ;==>_ObjError

Func _PrintMgr_AddTCPIPPrinterPort($sPortName, $sPortIP, $sPortNumber, $sProtocol = 1, $sSNMPEnabled = True, $sLPRQueue = Default, $sByteCount = Default, $sDisableBidi = False,$sPrinterName="" ) ; Protocol 1=RAW, 2=LPR
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If Not IsObj($oWMIService) Then Return SetError(1, 0, 0)
    Local $oNewPort = $oWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    If Not IsObj($oNewPort) Then Return SetError(1, 0, 0)
    $oNewPort.Name = $sPortName
    $oNewPort.Protocol = $sProtocol
    $oNewPort.HostAddress = $sPortIP
    $oNewPort.PortNumber = $sPortNumber
    If $sByteCount <> Default Then $oNewPort.ByteCount = $sByteCount
    If $sLPRQueue <> Default Then $oNewPort.Queue = $sLPRQueue
    If Not $sLPRQueue Then $oNewPort.SNMPEnabled = $sSNMPEnabled
    Local $ret = $oNewPort.Put_
    #forceref $ret
    If $sDisableBidi And ($sPrinterName<>"") Then Run('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /Xs /n "' & $sPrinterName & '" attributes -EnableBidi', @WindowsDir & "\System32", @SW_HIDE)
    If $_PrintMgr_ObjError=1 Then 
        $_PrintMgr_ObjError=0
        Return SetError(1, 0, $ret)
    EndIf
    Return 1
EndFunc   ;==>_PrintMgr_AddTCPIPPrinterPort

 

Edited by VIP
iRet

Regards,
 

  • 1 month later...
Posted

@VIP

Sorry fot the delay. I just checked the behaviour that you pointed out, and I didn't manage to reproduce the issue.

The printer was removed in both the Printer management and the Printers standard GUI

I think it's a display issue due to the use of #RequireAdmin in a non-admin user session.

 

 

 

 

 

  • 7 months later...
Posted (edited)

Hi all 

My Script  or Script to EXE works fine on my PC , but not on others. Could any one help review my code and give me some advice ?

#include <Array.au3>
#include "PrintMgr\PrintMgr.au3"


DriveMapAdd("P:", "\\192.168.2.78\Driver\Printer Driver")
_PrintMgr_AddPrinterDriver("Canon Generic Plus UFR II", "Windows NT x64", "P:\\GPlus_UFRII_Driver_V220_W64_2011\Driver","P:\\GPlus_UFRII_Driver_V220_W64_2011\Driver\CNLB0MA64.INF")
_PrintMgr_AddTCPIPPrinterPort("SDD-CANON-IR-ADV-C5550", "SDD-CANON-IR-ADV-C5550", 9100)
_PrintMgr_AddPrinter("iR-ADV C5550", "Canon Generic Plus UFR II", "SDD-CANON-IR-ADV-C5550")

_PrintMgr_SetDefaultPrinter("iR-ADV C5550")
DriveMapDel("P:")

here is the error message

I saw someone got the error too, I'm sure it's not about the permission. 

>"C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install\SciTe\..\AutoIt3.exe" "C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install\SciTe\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\AutoIT\AutoIT\GUI\MetroUDF-v5.1\MetroUDF-v5.1\MetroPrintinstall_Test.au3" /UserParams    
+>14:56:18 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (3.5.4.0)  Keyboard:00000404  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0404)  CodePage:950  utf8.auto.check:4
+>         SciTEDir => C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install\SciTe   UserDir => C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install\SciTe\AutoIt3Wrapper
>Running AU3Check (3.3.14.4)  from:C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install  input:C:\Users\Administrator\Desktop\AutoIT\AutoIT\GUI\MetroUDF-v5.1\MetroUDF-v5.1\MetroPrintinstall_Test.au3
+>14:56:19 AU3Check ended.rc:0
>Running:(3.3.14.4):C:\Users\Administrator\Desktop\AutoIT\AutoIT\autoit-v3\install\autoit3_x64.exe "C:\Users\Administrator\Desktop\AutoIT\AutoIT\GUI\MetroUDF-v5.1\MetroUDF-v5.1\MetroPrintinstall_Test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
"C:\Users\Administrator\Desktop\AutoIT\AutoIT\GUI\MetroUDF-v5.1\MetroUDF-v5.1\PrintMgr\PrintMgr.au3" (312) : ==> The requested action with this object has failed.:
$oPrinter.Put_
$oPrinter^ ERROR

->14:56:19 AutoIt3.exe ended.rc:1
+>14:56:19 AutoIt3Wrapper Finished.

>Process failed to respond; forcing abrupt termination...>Exit code: 2    Time: 4.491

 

Edited by aaronhunter
more information
Posted (edited)

 

This error could be related to Au3Check, so I do some review here:

https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer#methods

and I do not see such method property ".Put_"
 

Of coruse my investigation could be wrong.

 

EDIT:
running PrintMgr_Example.au3 without Au3Check
 

  Quote

OK
Line 312  (File "Z:\!!!_SVN_AU3\UDF_Forum\_Not_Used_Yet\PrintMgr\PrintMgr.au3"):

$oPrinter.Put_
$oPrinter^ ERROR

Error: The requested action with this object has failed.

Expand  

So this object doesn't have such a method property.

Edited by mLipok

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

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
×
×
  • Create New...