Jump to content

Recommended Posts

Posted

Where can I find $iportnumber for already installed printers?

I am used to the IP and Name when installing but not designating a port# so not sure what values I should be using.

 

Also for both display config and enumerate printers using array display is there a way to have a header on the data so you know the name of the values you are looking at?

Posted

To get the port number, you can use this :

; #FUNCTION# ====================================================================================================================
; Name ..........: _EnumTCPIPPrinterPort
; Description ...: Enumerate all TCP/IP printer ports
; Syntax ........: _EnumTCPIPPrinterPort([$sPortName = ""])
; Parameters ....: $sPortName - Name of the port to retrieve informations.
;                  Defaut "" returns informations for all ports.
; Return values .: Success - Returns an array containing all informations :
;                      $array[0][0] = 1st Port name
;                      $array[0][1] = 1st Port Host Address
;                      $array[0][2] = 1st Port Host Number
;                      $array[X][0] = Xth Port name
;                      [ ... ]
;                  Failure - Returns 0 and sets @eror to non-zero
; ===============================================================================================================================
Func _EnumTCPIPPrinterPort($sPortName = "")
    Local $aResult[1][10], $filter, $i = 0
    Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20

    If $sPortName <> "" Then $filter = " Where Name = '" & $sPortName & "'"

    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If NOT IsObj($objWMIService) Then Return SetError(1, 0, 0)

    $colPorts = $objWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort" & $filter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If NOT IsObj($colPorts) Then SetError(2, 0, 0)
    For $oPort In $colPorts
        $i += 1
        Redim $aResult[ $i][3]
        $aResult[$i - 1][0] = $oPort.Name
        $aResult[$i - 1][1] = $oPort.HostAddress
        $aResult[$i - 1][2] = $oPort.PortNumber
    Next
    If $i = 0 Then Return 0
    Return $aResult
EndFunc

For the header of the displayed array, just use $sHeader in the _ArrayDisplay :

$aPrintersConfig = _EnumPrinterConfiguration()
_ArrayDisplay($aPrintersConfig, "_EnumPrinterConfiguration", "", 0, Default, "BitsPerPel|Caption|Collate|Color|Copies|Description|DeviceName|DisplayFlags|DisplayFrequency|DitherType|DriverVersion|Duplex|FormName|HorizontalResolution|ICMIntent|ICMMethod|LogPixels|MediaType|Name|Orientation|PaperLength|PaperSize|PaperWidth|PelsHeight|PelsWidth|PrintQuality|Scale|SettingID|SpecificationVersion|TTOption|VerticalResolution|XResolution|YResolution")

 

  • 4 months later...
Posted (edited)

please help me.

how can i add printer,like "\\192.168.1.252\Brother HL-2130 series"?

Edited by ila
  • 4 months later...
Posted

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

I'm happy to share the new version of my PrintMgr UDF. All functions have been renamed, prefixed by _PrintMgr.
New features :
 - CancelAllJobs
 - EnumPrinter
 - Pause
 - PrinterExists
 - PrintTestPage
 - RenamePrinter
 - Resume

Please ask if any question

Posted

Please upload this UDF here:
https://www.autoitscript.com/forum/files/category/12-hardware/

Thanks.

 

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

Nice ICO :)

 

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

  • 4 weeks later...
Posted (edited)

I am using the below example script and this is what error returns:

#Include <Array.au3>
$aPrinterList = _PrintMgr_EnumPrinter()
_ArrayDisplay($aPrinterList)
"C:\AutoIt\Include\PrintMgr.au3" (206) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$aRet[$iCount] = $oPrinter.Name
^ ERROR

 

Edited by Kaimberex
Posted
  On 8/19/2016 at 8:27 PM, jguinch said:

@Kaimberex : I just updated my code, can you download the file again and retry ?

Expand  

I was able to get it to work another way for now I will update to new version and let you know. 

 

I do however have a question about _PrintMgr_SetDefaultPrinter. This function only seems to work on a Local printer not a network installed printer.  I am trying to set the below printer as a default and it returns 0 when setting the printer as default. I can get it to return 1 on locally installed printers just not network printers. I have tried using the FQDN of the printer. I have also just tried the ShareName. Neither works.

8-18-2016 9-43-13 AM.jpg

 

8-18-2016 9-49-37 AM.jpg

Posted (edited)
  On 8/24/2016 at 2:51 PM, jguinch said:

There was an error in the WMI query, fixed now (please download the updated file)

Yes, you have to use the share name for remote shared printers (I added a remarks in the function header)

Expand  

This still does not work. I have used the share name and the path to the network printer i.e \\Servername\Printer

Edited by Kaimberex
  • 1 month later...
Posted

Hi, i have been trying to get the _Printmgr_PrinterExists func to work but it couldn't get it to work, i took alook at the code and the only way i could get it to work is by adding this line into the function

$sPrinterName = StringReplace($sPrinterName, "\", "\\")

so now the function looks like this and this is how i can get it to work for me at least

Func _PrintMgr_RemovePrinter($sPrinterName)
    $sPrinterName = StringReplace($sPrinterName, "\", "\\")
    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 = '" & $sPrinterName & "'")
    If NOT IsObj($oPrinters) Then Return SetError(1, 0, 0)

    For $oPrinter in $oPrinters
        $oPrinter.Delete_()
    Next
    Return ( _Printmgr_PrinterExists($sPrinterName) ? 0 : 1)
EndFunc ; ==> _PrintMgr_RemovePrinter

hope this helps, or if i have messed something else up by doing this please let me know as i am an amateur and still have a very basic understanding.

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...