jguinch

Printers Management UDF

58 posts in this topic




Thanks for sharing. Might be useful someday.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks,guy!It's useful for me!


董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Share this post


Link to post
Share on other sites

Can be very useful here too. Once in a while I try to automate something with print queues and ports. I will have it a go in a few days.

Thanks jguinch

Share this post


Link to post
Share on other sites

I just came across this UDF and it looks very promising. I'd like to have some documentation on it. For instance, when adding a printer to a computer and I know the driver is not present on the machine, do I use the _AddPrinter or do I use the _AddPrinterDriver followed by the _AddPrinter? Do I need to install the driver first? If so, why is the final parameter only limited to the OS options of Win9x, Win351, NT40 and Win2k?

I'm trying to automate adding printers in various locations that do not have servers. All the clients are 64-bit Windows 7 and all printers will be direct TCP/IP port printing to a Canon imageRUNNER (various models).


Who lied and told you life would EVER be fair?

Share this post


Link to post
Share on other sites

Thank you for your interest.

Yes, you must install the driver first (with _AddPrinterDriver).

The default value for $sVersion parameter is 3 : it seems Windows 2000 and upper (in your case, I think). You will rarely have to install an old driver on a recent System... So you can use the default value.

For the $sDriverPlatform value, the values can be Windows NT x86 or Windows x64. (depending of the type of driver that you want to install).



 

Share this post


Link to post
Share on other sites

I made a script to get a list of all printers then remove them all. which works for the most part, but some printers are not removed and get greyed out with a yellow triangle on their icon. the property page is blank.


What is what? What is what.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Biatu : what type are printers that have not been removed ? Shared ?

In _RemovePrinter, you must use serverprinterShare for shared printers.

 

Nope, they are not shared, or network printers. they are connected via USB port. I test various printers, and the printer list gets pretty full so I run the script.

The issue used to be printer jobs from other users, so i made a func to remove all jobs from all printers.

Then another dell status service was locking some printers (afaik) so i stop the service.

that didnt work completely,so now I restart the spooler service, which remove most. all except for the "Dell 5330 Mono Laser MFP"

The env is win7 enterprise x64.

Edited by Biatu

What is what? What is what.

Share this post


Link to post
Share on other sites

_AddPrinter is not working either, i keep getting error dialog...

Error Number: -2147352567

WinDescription: Exception occurred.

Description: Generic Failure

Source: $WbemObjectEx

#Include <Printers.au3>

$Name="PrintNet.1"
$Driver="Dell 2335dn MFP,3,Windows x64"
$File="C:\Test1.pcl";@ScriptDir&"\"&$Name&".pcl"
_AddPrinter($Name,$Driver,"C:\Test1.pcl")

Thanks


What is what? What is what.

Share this post


Link to post
Share on other sites

Hello Guys,

 

I am new to autoit. I want  to run a program called PrinterInfo.exe, search for the the specific word " STATUS_PAPEROUT", if found then send email to desired recipient.

So far I have only able to run program, take a window capture save the window capture and then email the window capture to the recipient. But this is not what i want.

 

I have read posts which suggest that I should use WinGetText to retrieve the word, however I have still no idea as to how to search for the specific word " STATUS_PAPEROUT" and if present then send email.

 

Please help

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I use this to determine the printer type:

http://<Printer IP>:5200/Printer.xml

then i use the printer's network interface for everything else.

Currently i am doing research with PCL, SNMP, etc.

Edited by Biatu

What is what? What is what.

Share this post


Link to post
Share on other sites

Biatu, you have to install the driver before installing the printer : it could be done with _AddPrinterDriver (look at the example above).

Next, you have to know the port on which you want to install the printer (if needed, create a network port with _AddTCPIPPrinterPort.

And finally, you can add the printer...

I just downlod the Dell 2335dn MFP driver, so the installation can be done like this :

#Include "printers.au3"

Local $sPrinterName = "My Dell 2335dn Printer"
Local $sDriverName = "Dell 2335dn MFP"
Local $sPortIP = "192.168.1.250"
Local $sPortName = "IP_192.168.1.250"
Local $iPortnumber = 9100

_AddPrinterDriver($sDriverName, "Windows x64", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\", @ScriptDir & "\Printer\PCL\WINXP_VISTA_64\sdf1m.INF")
_AddTCPIPPrinterPort($sPortName, $sPortIP, $iPortnumber)
_AddPrinter($sPrinterName, $sDriverName, $sPortName)

Share this post


Link to post
Share on other sites

Thank you jguinch, will check out func on monday.


What is what? What is what.

Share this post


Link to post
Share on other sites

If I remove a printer using your func will I still need to remove port, or is that auto?

Thanks


What is what? What is what.

Share this post


Link to post
Share on other sites

_RemovePrinter does not remove the port. You must do it after.

Same thing for the driver.

Tried that, gives error. So i left it out, and the port does not show up on ports list when new printer is added or on the existing ones. So i assume that it's removed automatically


What is what? What is what.

Share this post


Link to post
Share on other sites

Hmm, is this a global (all users) add/delete of local (current profile)?

Speaking exclusively of printserver printers that normally only add per user, unlike local printesr that default to all users. 

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

  • Similar Content

    • ModemJunki
      By ModemJunki
      Hello,
      In Windows 10 PowerShell, one can do this to change the metric for a NIC in Windows 10:
      Get-NetAdapter | Where-Object -FilterScript {$_.InterfaceAlias -Eq "Ethernet 2"} | Set-NetIPInterface -InterfaceMetric 2 I know I can script the above PowerShell line (and it works!), but I wanted to try something I hadn't done before after looking into jguinch's most excellent Network configuration UDF. I wanted to make use of the SetIPConnectionMetric method in the WMI classes. There is an example VBscript here but this is not for Windows 10. Using AutoIT would also give better control over capturing error return codes than with PowerShell.
      But I cannot get my script to work! The return from SetIPConnectionMetric() is 0, which would indicate success. Yet the change does not happen. I also tried WMI methods using .put_ but this fails.
      Anyone more experienced than I have ideas to make this work?
      #RequireAdmin _SetNicInterfaceMetric2("Ethernet 2", "2") Func _SetNicInterfaceMetric2($NIC_NAME, $METRIC) Local $s_setIndx = 0 $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") $colNICItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & $NIC_NAME & "'", "WQL") If IsObj($colNICItems) Then For $objItem In $colNICItems $s_nicIndex = $objItem.Index Next ConsoleWrite("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'" & @CRLF) $colNAC = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'", "WQL") If IsObj($colNAC) Then For $objNetCard In $colNAC If $METRIC <> $objNetCard.IPConnectionMetric Then ConsoleWrite("Metric was set to " & $objNetCard.IPConnectionMetric & ". Setting to " & $METRIC & "." & @CRLF) $s_isSet = $objNetCard.SetIPConnectionMetric($METRIC) ConsoleWrite("SetIPConnectionMetric Result = " & $s_isSet & @CRLF) Else ConsoleWrite("Metric is already set to " & $METRIC & @CRLF) EndIf Next EndIf EndIf EndFunc ;==>_SetNicInterfaceMetric2  
    • AndyS19
      By AndyS19
      I have code that does a WMI SQL query to find all defined printers, and I want to parse the returned object in several places.  However, after parsing it the first time, all other times fail to find any printer objects.
      Here is my test code:
      test() Func test() Local $oPrinters, $oPrinter, $err, $cnt, $oP, $query $query = "SELECT * FROM Win32_Printer" $oPrinters = doQuery($query) $err = @error LogMsg("+++: $err = " & $err & ", isObj($oPrinters) = " & IsObj($oPrinters)) If ($err == 0) Then LogMsg("FIRST LOOP") ; <=== FIRST LOOP $cnt = 0 $oP = $oPrinters LogMsg("+++: isObj($oP) = " & IsObj($oP)) For $oPrinter In $oP $cnt += 1 LogMsg("+++: isObj($oPrinter): " & IsObj($oPrinter) & ", $oPrinter.Name ==>" & $oPrinter.Name & "<==") Next LogMsg("+++: Found " & $cnt & " printers") LogMsg("SECOND LOOP") ; <== SECOND LOOP $cnt = 0 $oP = $oPrinters LogMsg("+++: isObj($oP) = " & IsObj($oP)) For $oPrinter In $oP $cnt += 1 LogMsg("+++: isObj($oPrinter): " & IsObj($oPrinter) & ", $oPrinter.Name ==>" & $oPrinter.Name & "<==") Next LogMsg("+++: Found " & $cnt & " printers") EndIf EndFunc ;==>test Func doQuery($sQuery, $lnum = @ScriptLineNumber) #forceref $lnum LogMsg("+++:" & $lnum & ": doQuery(" & '"' & $sQuery & '"' & ") entered") Local $oWMIService, $oResults, $errstr Local $wbemFlags = BitOR(0x20, 0x10) ; $wbemFlagReturnImmediately and wbemFlagForwardOnly $oWMIService = ObjGet("winmgmts:\\" & "localhost" & "\root\CIMV2") If (IsObj($oWMIService)) Then $oResults = $oWMIService.ExecQuery($sQuery, "WQL", $wbemFlags) If (IsObj($oResults)) Then LogMsg("+++: doQuery() returns @error = 0, Good: returning the object") Return (SetError(0, 0, $oResults)) ;;; Good: return the object Else $errstr = "" _ & "WMI Query failed." & @CRLF _ & "This is the query:" & @CRLF _ & " " & $sQuery LogMsg("+++: ====>" & $errstr & "<===") LogMsg("+++: doQuery() returns @error = 1") Return (SetError(1, 0, $errstr)) ; Error: Query faled EndIf Else $errstr = "" _ & "WMI Output" & @CRLF _ & "No WMI Objects Found for class: " & @CRLF _ & "Win32_PrinterDriver" & @CRLF _ & "using this query:" & @CRLF _ & " " & $sQuery LogMsg("+++: ====>" & $errstr & "<===") MsgBox(0, "ERROR", $errstr) ; Error: Cannot get $oWMIService object Exit (1) EndIf EndFunc ;==>doQuery Func LogMsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>LogMsg Parsing the returned $oPrinters object shows 5 printers:
      +++:15: FIRST LOOP +++:18: +++: isObj($oP) = 1 +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Microsoft XPS Document Writer<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Microsoft Office Document Image Writer<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Fax<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Canon MG7100 series Printer WS<== +++:22: +++: isObj($oPrinter): 1, $oPrinter.Name ==>Canon MG6100 series Printer WS<== +++:24: +++: Found 5 printers Parsing it again, shows no printers:
      +++:26: SECOND LOOP +++:29: +++: isObj($oP) = 1 +++:35: +++: Found 0 printers  
    • jguinch
      By jguinch
      Here is an UDF for managing printers.
      Features are :
       - add, remove or rename a printer
       - add or remove a driver
       - add or remove a TCP/IP printer port
       - add or remove a LPR printer port
       - connect to a remote printer
       - enum printers and there configuration and properties
       - pause resume or cancel all jobs of a printer
       - checks if a printer exists
       - print a test page
       - set the default printer
    • ripdad
      By ripdad
      This function (version 1), was developed solely for applications I needed it for.
      It was only tested with Class names that was needed in those scripts.
      And so, I didn't want to release it by itself because I knew it needed some more
      work before I did that.
      Recently, I delved back into it after several years and am now releasing version 2,
      which was mostly rewritten over the past several weeks.
      What does it do? It retrieves the properties and values pertaining to your computer,
      operating system and devices. All you need is a valid Win32 Class Name.
      So, here it is -- let me know if you have any issues!
      Updated to v2.25, January 14, 2017
      Download: _WMI_InstancesOf_v2.25.au3
       
    • TMelanson
      By TMelanson
      Hi folks,
      I'm hoping someone can help me out here.
      Background:
      I have the need to run a program with admin credentials (#RequireAdmin), and then get the SID of the locally logged in account. Not the admin account.
      If you look at the attached script, Line 16 uses the @UserName variable and returns the SID for the admin account I used to launch the app.
      I want to use line 17 which passes the result of the _GetUsername function which is a username using  ($UserName) to the WMIService.
      I'm getting " The requested action with this object has failed.:" error message.
      Any suggestions would be appreciated!
       
      test1.au3