Jump to content

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?

Link to post
Share on other sites
  • Replies 111
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hello. I did create these few functions several months ago. I post here, if it can interest someone. These functions based on WMI queries allow you to manage printers : add / delete printer, drive

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)

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

Posted Images

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

 

Link to post
Share on other sites
  • 4 months later...
  • 4 months later...

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 * 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 * Include Dependency Tree (Tool for analyzing script relations) *

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 *

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: 2021-10-18

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.

 

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

Link to post
Share on other sites

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 * 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 * Include Dependency Tree (Tool for analyzing script relations) *

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 *

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: 2021-10-18

Link to post
Share on other sites

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 * 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 * Include Dependency Tree (Tool for analyzing script relations) *

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 *

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: 2021-10-18

Link to post
Share on other sites
  • 4 weeks later...

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

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)

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
Link to post
Share on other sites
  • 1 month later...

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.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By hek
      Hey everyone,
      Was wondering how I would be able to implement this on a local computer instead of using connectserver? 
      Any suggestions or help would be appreciated. Thanks. 
    • By DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      Original:
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • 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

×
×
  • Create New...