Jump to content

Printer functionality


Wooltown
 Share

Recommended Posts

Guest BinaryVision

Seems interesting. Where would you specify what built-in or external driver to use for the printer? Do you know anything about adding TCP/IP ports and printers mapped to them? I have been doing it the old fashioned way for a while now, with something along these lines...

;===========================================================================================
;  This script adds network printers based on five distinct variables:
;
;   $ipaddress  Printer network IP address
;   $listmfg    Printer manufacturer as listed in the Add Printer Wizard,
;               not case-sensitive
;   $listname   Printer name as listed in the Add Printer Wizard or 
;               driver default name, not case-sensitive
;   $addname    (Optional) Printer name visible to users only if different
;               from default name, else leave "" (empty string) or skip
;   $driverpath (Optional) Path to directory containing printer driver,
;               else leave "" (empty string) or skip
;
;  Important Notes: Make sure $listmfg and $listname are spelled correctly or script
;                   will load driver unless $driverpath is not specified 
;===========================================================================================


If @OSVersion <> "WIN_2000" And @OSVersion <> "WIN_XP" Then
  MsgBox(16,"Error","This script only supports Windows 2000 and XP")
  Exit
EndIf

Dim $ipaddress,$listmfg,$listname,$addname,$driverpath,$addcount,$skipcount,$itemindex

$addcount = 0
$skipcount = 0

;*******************************************************************************************
;*  ADD PRINTER VARIABLES AND ADDPRINTER FUNCTION BELOW
;*******************************************************************************************

$ipaddress = "192.168.1.16"
$listmfg = "hp"
$listname = "hp laserjet 5si"
AddPrinter()

$ipaddress = "192.168.1.17"
$listmfg = "hp"
$listname = "hp laserjet 5si mx"
AddPrinter()

$ipaddress = "192.168.1.18"
$listmfg = "hp"
If @OSVersion = "WIN_2000" Then
  $listname = "hp laserjet 8150 pcl 6"
Else
  $listname = "hp laserjet 8150 series pcl"
EndIf
$addname = "HP LaserJet 8150 - East"
$driverpath = "\\xxxxx\software$\_DRIVERS\HP LaserJet 8150"
AddPrinter()

$ipaddress = "192.168.1.19"
$listmfg = "hp"
$listname = "hp color laserjet 4550 pcl"
$addname = "HP Color LaserJet 4550"
$driverpath = "\\xxxxx\software$\_DRIVERS\HP Color LaserJet 4550"
AddPrinter()

$ipaddress = "192.168.1.20"
$listmfg = "hp"
If @OSVersion = "WIN_2000" Then
  $listname = "hp laserjet 8150 pcl 6"
Else
  $listname = "hp laserjet 8150 series pcl"
EndIf
$addname = "HP LaserJet 8150 - West"
$driverpath = "\\xxxxx\software$\_DRIVERS\HP LaserJet 8150"
AddPrinter()

;*******************************************************************************************
;*  STOP HERE! DO NOT ADD OR EDIT ANY CODE BELOW THIS LINE
;*******************************************************************************************

If $skipcount = 0 Then
  MsgBox(64,"Printer Script",$addcount & " printers were added.")
Else
  MsgBox(64,"Printer Script",$addcount & " printers were added and " & $skipcount & " printers were skipped.")
EndIf

Exit

Func LoadDriver();when printer driver is not already loaded
  ControlClick("last","",1567);click 'Have Disk...'
  WinWaitActive("Install From Disk","&Copy manufacturer's files from")
  ControlSetText("last","",1001,$driverpath)
  ControlClick("last","",1);click OK
  WinWaitActive("Add Printer Wizard","Select the manufacturer and model")
EndFunc

Func AddPrinter()
 If $ipaddress = "" Or $listmfg = "" Or $listname = "" Then
  MsgBox(48,"Error","One or more required variables for a printer is missing or blank.")
  Exit
 Else
  $pid = Run(@SystemDir & "\rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter")
  WinWaitActive("Add Printer Wizard","Welcome to the Add Printer Wizard")
  ControlClick("last","",12325)
  WinWaitActive("Add Printer Wizard","Select the option that describes")
  ControlCommand("last","",3510,"Check","");select 'Local printer attached...'
  ControlCommand("last","",4665,"UnCheck","")
 ;uncheck 'Automatically detect and install my Plug and Play printer'
  ControlClick("last","",12325)
  WinWaitActive("Add Printer Wizard","Select the port you want")
  ControlCommand("last","",4558,"Check");select 'Create a new port'
  Send("s");select 'Standard TCP/IP Port' for type
  ControlClick("last","",12325)
  WinWaitActive("Add Standard TCP/IP Printer Port Wizard","Welcome")
  ControlClick("last","",12325)
  WinWaitActive("Add Standard TCP/IP Printer Port Wizard","Enter the Printer Name or")
  ControlSetText("last","",1000,$ipaddress)
  Sleep(1000);allow time to refresh port name
  ControlClick("last","",12325)
  If WinWaitActive("Error","A port with that name already exists.",2) Then
;if ip address already exists, error message will popup
    Send("{ENTER}");click OK
    WinWaitActive("Add Standard TCP/IP Printer Port Wizard","")
    ControlClick("Add Standard TCP/IP Printer Port Wizard","",2);click Cancel
    WinWaitActive("Add Printer Wizard","")
    ControlClick("Add Printer Wizard","",2);click Cancel
    $skipcount = $skipcount + 1;count 1 printer skipped
  Else
    WinWaitActive("Add Standard TCP/IP Printer Port Wizard","Summary")
    ControlClick("last","",12325)
    WinWaitActive("Add Printer Wizard","Select the manufacturer and model")
    $itemindex = ControlListView("Add Printer Wizard","",1580,"FindItem",$listmfg)
 ;returns item index (number) of manufacturer from the built-in list
    If $itemindex = -1 Then
      If $driverpath = "" Then
        MsgBox(48,"Error","The manufacturer " & $listmfg & " for " & $listname & " was not _
         found and no driver was specified." & @CR & "Check the manufacturer name or _
         specify a driver and re-run this script to continue.")
        Exit
      EndIf
      LoadDriver()
    Else
      ControlListView("Add Printer Wizard","",1580,"Select",$itemindex)
      Sleep(1000);allow time to refresh model list
      $itemindex = ControlListView("Add Printer Wizard","",1581,"FindItem",$listname)
;returns item index (number) of printer name from the built-in list
      If $itemindex = -1 Then
        If $driverpath = "" Then
      MsgBox(48,"Error","The printer " & $listname & " was not found and no driver was _
       specified." & @CR & "Check the printer name or specify a driver and re-run this _
       script to continue.")
      Exit
        EndIf
        LoadDriver()
      Else
        ControlListView("Add Printer Wizard","",1581,"Select",$itemindex)
      EndIf
    EndIf     
    ControlClick("last","",12325)
    If WinWaitActive("Add Printer Wizard","keep the existing driver or",2) Then
      ControlCommand("last","",3550,"Check");select 'Keep existing driver (recommended)'
      ControlClick("last","",12325)
    EndIf
    WinWaitActive("Add Printer Wizard","Type a name for this printer")
    If $addname <> "" Then
      ControlSetText("last","",1046,$addname);set printer name
    EndIf
    ControlCommand("last","",3521,"Check");select No for make printer default
    ControlClick("last","",12325)
    WinWaitActive("Add Printer Wizard","If you want to share this printer")
    ControlCommand("last","",3227,"Check");select 'Do not share this printer'
    ControlClick("last","",12325)
    WinWaitActive("Add Printer Wizard","Do you want to print a test page?")
    ControlCommand("last","",3521,"Check");select No for printing a test page
    ControlClick("last","",12325)
    WinWaitActive("Add Printer Wizard","Completing the Add Printer Wizard")
    ControlClick("last","",12325)
    $addcount = $addcount + 1;count printer as added
  EndIf
  ProcessWaitClose($pid);wait for printer wizard to close
  $ipaddress = "";clean variables
  $listmfg = ""
  $listname = ""
  $addname = ""
  $driverpath = ""
  $itemindex = ""
 EndIf
EndFunc
Edited by BinaryVision
Link to comment
Share on other sites

Hello !

In the script, the only thing you do is to connect to the printer on the other computer, and you use the drvier on that computer, no driver is then needed to install on your own computer.

The advantage is that you only need to install the driver on one place, and upgrade in the same place.

The printer queue resides on the computer to which you connect, and is a shared printer.

/Sven

Link to comment
Share on other sites

Guest BinaryVision

Hello !

In the script, the only thing you do is to connect to the printer on the other computer, and you use the drvier on that computer, no driver is then needed to install on your own computer.

The advantage is that you only need to install the driver on one place, and upgrade in the same place.

The printer queue resides on the computer to which you connect, and is a shared printer.

/Sven

We do not use a print server with our printers (one less server to maintain). So the printers are connected using the Jet Direct built-in print servers to the local network with a local IP.

Link to comment
Share on other sites

If you put the printer queues on one server instead of on each, the adminstration is much more easier, you can have any Windows 2000/2003 server as a print server, the workload for printer handling is very low.

If you for example have 200 workstations and there is some kind of error in the driver then you have 200 places instead of 1 to update.

/Sven

Link to comment
Share on other sites

  • 1 year later...

Added 4 printer functions to AutoIT

_PrinterAdd

Connect to a network printer

_PrinterDefault

Set a printer to defualt

_PrinterDelete

Delete a printer connection

_PrinterExist

Test if a printer exist

Examples included

/Sven

How do you delete all the printers?

In Kixscripts it would be

DelPrinterConnection ("")

Link to comment
Share on other sites

  • 3 years later...

Added 4 printer functions to AutoIT

_PrinterAdd

Connect to a network printer

_PrinterDefault

Set a printer to defualt

_PrinterDelete

Delete a printer connection

_PrinterExist

Test if a printer exist

Examples included

/Sven

One problem ... when using a FQDN for the server, as needed in some domains, the WMI script that does the Exist Check will fail to see the FQDN since it'll be stored in WMI as the short name of the server. I tweak to the script would fix it on a per user basis. Great foundation, though!

Figure IT out!http://vertigion.com

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...