Jump to content

Printers Management UDF


jguinch
 Share

Recommended Posts

@jguinch Could you please edit your signature, by re-edit sopiler (currently is always unfloded).

 

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:

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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

This is normal spoiler, but your seams to be broken. I had the same problem some time ago.
Fixing is simple just re-edit your signature.

 

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:

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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

btw.
Sometimes HP products are installing printers not with port like USB0001 or 192.168.0.xx but like this HPXKFJD123441.

My question is:
How to check if any installed printer is using such kind of port ? (of course I'm asking how to check it using this UDF )
 

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:

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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Like this (use this one to list all printers and there port):

#include "PrintMgr.au3"

Local $aPrinters = _PrintMgr_EnumPrinter()

For $i = 1 To $aPrinters[0]
    $aProperties = _PrintMgr_EnumPrinterProperties($aPrinters[$i])
    $sPortname = $aProperties[0][60]

    ConsoleWrite("Printer '" & $aPrinters[$i] & "' on port '" & $sPortname & "'" & @CRLF)
Next

This one lists all printers that do not use a local port (port name like USB001: or LPT1:) and do not use a TCP/IP port :

#include "PrintMgr.au3"

Local $aPrinters = _PrintMgr_EnumPrinter()
Local $aTCPIPPorts = _PrintMgr_EnumTCPIPPrinterPort()
Local $iIsNetPrinter

For $i = 1 To $aPrinters[0]
    $iIsNetPrinter = 0
    $aProperties = _PrintMgr_EnumPrinterProperties($aPrinters[$i])
    $sPortname = $aProperties[0][60]

    For $j = 0 To UBound($aTCPIPPorts) - 1
        If $sPortname = $aTCPIPPorts[$j][0] Then
            $iIsNetPrinter = 1
            ExitLoop
        EndIf
    Next

    If Not $iIsNetPrinter And Not StringRegExp($sPortname, ":$") Then ConsoleWrite("Printer '" & $aPrinters[$i] & "' on port '" & $sPortname & "'" & @CRLF)
Next

 

Edited by jguinch
Link to comment
Share on other sites

Thanks.
Will check this later on desired system.

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:

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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Edit 2017/01/31 : Added functions _Printmgr_AddLPRPort and _Printmgr_RemoveLPRPort

Edit 2017/04/02 : Added functions _Printmgr_EnumPorts, _Printmgr_PortExists, _Printmgr_PrinterSetDriver and _Printmgr_PrinterSetPort . Special thanks to @Danyfirex for his contribution with EnumPorts.

Edited by jguinch
Link to comment
Share on other sites

On 31.01.2017 at 11:50 PM, mLipok said:

Thanks.
Will check this later on desired system.

mLipok

Thanks again.
This looks like:

Quote

! Example 1
Printer 'PDFCreator' on port 'pdfcmon'
Printer 'Microsoft XPS Document Writer' on port 'PORTPROMPT:'
Printer 'Microsoft Print to PDF' on port 'PORTPROMPT:'
Printer 'HP LaserJet P2055x UPD PS (Copy 2)' on port 'WSD-97f7230b-0329-4adf-9214-d21ea010a046.0031'
Printer 'HP LaserJet P2055x UPD PS (Copy 1)' on port 'WSD-cc5bd9bd-b726-4f3c-a41e-4224f5b10ad6.0030'
Printer 'HP LaserJet P2055x UPD PS' on port 'WSD-41135643-1dca-4994-a0a5-0e9648d515e2.0068'
Printer 'Fax' on port 'SHRFAX:'
Printer 'D2 Koperty' on port 'IP_192.168.100.202'
Printer 'D2' on port 'IP_192.168.100.202'
Printer 'D1 Koperty' on port '192.168.100.201'
! Example 2
Printer 'PDFCreator' on port 'pdfcmon'
Printer 'HP LaserJet P2055x UPD PS (Copy 2)' on port 'WSD-97f7230b-0329-4adf-9214-d21ea010a046.0031'
Printer 'HP LaserJet P2055x UPD PS (Copy 1)' on port 'WSD-cc5bd9bd-b726-4f3c-a41e-4224f5b10ad6.0030'
Printer 'HP LaserJet P2055x UPD PS' on port 'WSD-41135643-1dca-4994-a0a5-0e9648d515e2.0068'
Printer 'D2 Koperty' on port 'IP_192.168.100.202'
Printer 'D2' on port 'IP_192.168.100.202'

Here is full testing snippet:
 

#include "PrintMgr.au3"

_Example1()
_Example2()
_Example3()

Func _Example1()
    ConsoleWrite("! Example 1" & @CRLF)
    Local $aPrinters = _PrintMgr_EnumPrinter()

    For $i = 1 To $aPrinters[0]
        $aProperties = _PrintMgr_EnumPrinterProperties($aPrinters[$i])
        $sPortname = $aProperties[0][60]

        ConsoleWrite("Printer '" & $aPrinters[$i] & "' on port '" & $sPortname & "'" & @CRLF)
    Next


EndFunc   ;==>_Example1

Func _Example2()
    ConsoleWrite("! Example 2" & @CRLF)

    Local $aPrinters = _PrintMgr_EnumPrinter()
    Local $aTCPIPPorts = _PrintMgr_EnumTCPIPPrinterPort()
    Local $iIsNetPrinter

    For $i = 1 To $aPrinters[0]
        $iIsNetPrinter = 0
        $aProperties = _PrintMgr_EnumPrinterProperties($aPrinters[$i])
        $sPortname = $aProperties[0][60]

        For $j = 0 To UBound($aTCPIPPorts) - 1
            If StringInStr($sPortname, $aTCPIPPorts[$j][0]) <> 0 Then
                $iIsNetPrinter = 1
                ExitLoop
            EndIf
        Next

        If Not $iIsNetPrinter And Not StringRegExp($sPortname, ":$") Then ConsoleWrite("Printer '" & $aPrinters[$i] & "' on port '" & $sPortname & "'" & @CRLF)
    Next
EndFunc   ;==>_Example2

Func _Example3()

EndFunc   ;==>_Example3

 

As you can see I had to change your second example a little, by using:
 

If StringInStr($sPortname, $aTCPIPPorts[$j][0]) <> 0 Then

This is due to the fact that $sPortname can be prefixed by 'IP_' in result I have 'IP_192.168.100.202'

<hr>

Questions:


Why I can not manually change port on:
Printer 'HP LaserJet P2055x UPD PS (Copy 2)' on port 'WSD-97f7230b-0329-4adf-9214-d21ea010a046.0031'

I see that in the printer driver properties window, all options in "Ports" tab are disabled / grayed out. But why ?

And: Could I change this port in such cases, by using this UDF  ?

 

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:

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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

I don't really understand why you had to change my code ( As you can see I had to change your second example a little, by using: ), because it compares the printer port name with each TCPIP port name....

For you questions :
 - If the options are grayed out, it can be a problem with rights access. Check it in the Security tab or use an admin account (I think it's already the case...)
 - You can try _Printmgr_PrinterSetPort  to apply another port to your printer.

 

Link to comment
Share on other sites

  • 1 month later...

 

@jguinch

Thanks for sharing this UDF. It is fantastic!

I need to be able to get the current status of the printer (if it is paused or not) so I can tell the user in a tooltip and then allow the user to toggle the status with a hotkey.

I tried using _Printmgr_Pause expecting that if the printer was already paused it would return an error, but unfortunately that is not the case. _Printmgr_Pause returns success even if the printer is already paused.

Do you have any suggestions?

Thanks!

Marcus.

Link to comment
Share on other sites

I ended up adding this function to your UDF. Hopefully you can fine tune it and add to the official release.

; #FUNCTION# ======================================================================================
; Name...........: _Printmgr_GetStatus
; Description ...: Gets current status of a printer
; Syntax.........:  _Printmgr_GetStatus($sPrinterName)
; Parameters ....: $sPrinterName - Name of the printer
; Return values .: Success - Returns the status string
;                  Failure - Returns empty string
; =================================================================================================
Func _Printmgr_GetStatus($sPrinterName)
    Local $iRet = 19, $aRet[$iRet+1]
    $aRet[1]='Other'
    $aRet[2]='Unknown'
    $aRet[3]='Idle'
    $aRet[4]='Printing'
    $aRet[5]='Warmup'
    $aRet[6]='Stopped Printing'
    $aRet[7]='Offline'
    $aRet[8]='Paused'
    $aRet[9]='Error'
    $aRet[10]='Busy'
    $aRet[11]='Not Available'
    $aRet[12]='Waiting'
    $aRet[13]='Processing'
    $aRet[14]='Initialization'
    $aRet[15]='Power Save'
    $aRet[16]='Pending Deletion'
    $aRet[17]='I/O Active'
    $aRet[18]='Manual Feed'
    $aRet[19]=''
    Local Const $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If NOT IsObj($oWMIService) Then Return SetError(1, 0, 0)
    Local $oPrinters = $oWMIService.ExecQuery ("Select * from Win32_Printer Where DeviceID like '" & $sPrinterName & "'", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If NOT IsObj($oPrinters) Then Return SetError(1, 0, 0)
    For $oPrinter in $oPrinters
        $iRet = $oPrinter.ExtendedPrinterStatus()
    Next
    ;MsgBox(0,$iRet,"")
    ;MsgBox(0,$iRet,$aRet[$iRet])
    Return ($aRet[$iRet])
EndFunc ; ==> _Printmgr_GetStatus

 

Thanks!

Edited by marcusvdt
Small fixes in the code.
Link to comment
Share on other sites

  • 4 weeks later...

Hello!

In the Script "_PrintMgr_AddWindowsPrinterConnection" is a Error:

Local $oPrinter = $oWMIService("Win32_Printer")
Local $oPrinter = $oWMIService^ ERROR

Correct:

Func _PrintMgr_AddWindowsPrinterConnection($sPrinterPath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If NOT IsObj($oWMIService) Then Return SetError(1, 0, 0)
    Local $oPrinter = $oWMIService.get("Win32_Printer")
    If NOT IsObj($oPrinter) Then Return SetError(1, 0, 0)
    Local $iRet = $oPrinter.AddPrinterConnection($sPrinterPath)
    Return ( $iRet = 0 ? 1 : SetError($iRet, 0, 0))
EndFunc ; ==> _PrintMgr_AddWindowsPrinterConnection

 

Sorry for bad english...

bg
Racer

 

Link to comment
Share on other sites

  • 3 months later...

Hello, thank you for your wonderful UDF

Tell me how to solve this problem

If used

#RequireAdmin
Then everything is fine


If not then I get a crash and an error in the code
 

PrintMgr.au3" (117) : ==> The requested action with this object has failed.:
$oPrinter.Put_
$oPrinter^ ERROR
->09:06:21 AutoIt3.exe ended.rc:1
+>09:06:21 AutoIt3Wrapper Finished.


I found out that this problem is caused by the fact that without the administrator rights the printer driver is not added, due to which when adding the printer itself there is no $ oPrinter.Put_


What can you do to not crash, and
Output an error message?

print_test_install_v3.au3

Link to comment
Share on other sites

2 hours ago, jguinch said:

Use ObjEvent to intercept the COM errors (look at the help page of ObjEvent)

 

Can you write how to solve the problem? I looked up the help, but I could not figure out how to apply it correctly.

Link to comment
Share on other sites

  • 4 months later...

I am very new to AutoIT, so please be gracious ;-) I must be missing something simple. I am downloading a print driver that is a zip self extracting archive. I have gotten to the point of being able to add the print driver and it simple is not working.

Here is the line:
_PrintMgr_AddPrinterDriver("PCL6 Driver for Universal Print", "Windows NT x86", "c:\temp\z81459L17\disk1", "c:\temp\z81459L17\disk1\oemsetup.inf")
I am getting an error in event viewer:

 

Label PSetupInstallPrinterDriver
   
  Message InstallDriverFromCurrentInf failed
   
  AdditionalInfo -
   
  InfPath c:\temp\z81459l17\disk1\oemsetup.inf
   
  DriverName -
   
  InstallSection -
   
  ProcessorArchitecture Windows NT x86
   
  PackageAware Not package aware
   
  CoreDriverDependencies -
   
  LastError 0x5
   
  HResult 0x80070005

 

The disk path is correct, I have set the name in the script from the drvname that is in the oemsetup.inf. I am sure that I am missing something really simple here.

Installing on a Windows 10 Professional machine.

Link to comment
Share on other sites

_Printmgr_PrintTestPage , that would have been nice, if you can add an additional parameter to add the pc  name where the test print is  being done. May be a banner option

ie   _Printmgr_PrintTestPage($sPrinterName, $computername)

Edited by antonioj84
error
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...