Jump to content
Sign in to follow this  
jguinch

Printers Management UDF

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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")

 

Share this post


Link to post
Share on other sites

please help me.

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

Edited by ila

Share this post


Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library *

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 * 

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

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 *

"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: 2019-10-01

Share this post


Link to post
Share on other sites

Thanks mLipok for the link on the wiki.

@Cyberonimo, I don't understand what you want (add local print server ???). If you want to add a local printer, just use_AddPrinter and specify a local port.

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Thanks.

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library *

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 * 

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

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 *

"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: 2019-10-01

Share this post


Link to post
Share on other sites

Nice ICO :)

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library *

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 * 

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

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 *

"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: 2019-10-01

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
On 8/19/2016 at 3:27 PM, jguinch said:

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

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
On 8/24/2016 at 9:51 AM, 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)

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

Share this post


Link to post
Share on other sites
1 minute ago, Kaimberex said:

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

I got it to work, but you have to use the FQDN of the print server i.e \\Servername.domain.com\Printer name.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By shital
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** RunAs(test", @ComputerName, "testinng",2,"wmic product where ""name= '%notepadexamples%'"" call uninstall", @SystemDir & "\wbem", @SW_MAXIMIZE)  it not working 
       
    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By jresine
      Hello, is it possible to know via a script or command, to have the percentage of disk usage of a process? thank you in advance.
      ps: see image

    • By Dwalfware
      HI
      Another head scratched
      Anyone solve how to get the IPV6 from WMI?
      I followed the usual SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID='" & GUICtrlRead($cboAdapters) & "'
      get the index 
      port it to 
      Local $query = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 )
      All i can see is IPv4 addresses
      My question is is there another place the IPv6 information is hiding? I configured my LAN with IPV6 and my wireless with IPv4 so I can see what shows.
      Thanks in Advance.
      PS. I did try google
       
    • By Dwalfware
      Hi Folks
      Can not get my head around this one.
      This function gets the DNS object s
      If you have two DNS entries fine. but if you have only one! Trouble
      $objItem.DNSServerSearchOrder[0] = Primary DNS
      $objItem.DNSServerSearchOrder[1] = Secondry DNS not always there. I need a way to return 0 if not there or the IP if its there.
      Or is there a way to tell how many objects there are in the "[?]"
      I'm terrible at WMI errors, thanks for help in advance.
      Func _GETcurrentNICinfo2() $oErrors = ObjEvent("AutoIt.Error", "Error_Handle") Local $DnsSecondry Local $objWMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\CIMV2" ) Local $query = $objWMIService.ExecQuery("SELECT DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 ) If @error Then Return 0 If NOT IsObj($query) Then Return 0 Else For $objItem In $query Return $objItem.DNSServerSearchOrder[1] next Endif EndFunc  
×
×
  • Create New...