Jump to content

Printer Tool


kpu
 Share

Recommended Posts

I'm sure there are tools that do what I've done, maybe even better. I just thought some green horn like myself might find useful.

WHAT IT DOES

1. Reads "printer.ini" and creates a *.vbs (windows scripting) file to create the ports needed. You will need sscreen.gif to see a splash screen. Edit $destination = "sscreen.gif" to point to the correct graphic.

This is composed of 2 tools:

1. Is the INI_Writer

2. Is the tool that reads the printer.ini file. Make sure you name it "printer.ini"

THE INI WRITER CODE:

#include <file.au3>


; Writing INI for Printer Information
$ini = inputBox("Printer INI","What is the name of the ini you want to create","printer.ini")
    IF @error = 1 then
        MsgBox(0, "Closing", "Good Bye")
        Exit
    Endif
_FileCreate($ini)
;Ask for the Printer Que name
$printer = InputBox("Print Que","What is the printer que name?","PRINTER_2_HP4050TN_Q")
    IF @error = 1 then
        MsgBox(0, "Closing", "Good Bye")
        Exit
    Endif
;Ask for Printer IP 
$ip = InputBox("Printer IP","What is the printer IP?","10.20.70.256")
    IF @error = 1 then
        MsgBox(0, "Closing", "Good Bye")
        Exit
    Endif
;Ask for Drive location 
$driver = InputBox("Printer Drivers","Where is the location of the printer?" & @CR & _
"Press 1 for HP5M" & @CR & "Press 2 for HP4000TN" & @CR & "Press 3 for HP4050TN" & @CR _
& "Press 4 for HP4100TN" & @CR & "Press 5 for HP4200 Series","")
    IF @error = 1 then
        MsgBox(0, "Closing", "Good Bye")
        Exit
    Endif
;Carry out task
IF $driver = "1" Then;HP5M
    $drv = "\\XP-W2k\lj456p5.inf";put the network path to the drivers here.
    $dis = "HP LaserJet 5M" 
ElseIf $driver = "2" Then; HP4000TN 
    $drv = "\\WINXP-2K\PCL 5e driver\HP4000P5.INF" 
    $dis = "HP LaserJet 4000 Series PCL 5e"
ElseIf $driver = "3" Then;HP4050TN 
    $drv = "\\\HP\HP 4050tn\W2K\HP001Ip5.inf" 
    $dis = "HP LaserJet 4050 Series PCL 5e"
ElseIf $driver = "4" Then;HP4100TN 
    $drv = "\\2K_XP PCL5e\hp4100p5.inf"
    $dis = "HP LaserJet 4100 PCL 5e"
ElseIf $driver = "5" Then;HP4250TN 
    $drv = "\\HP\HP 4250-4350\hpc4200b.inf"
    $dis = "hp LaserJet 4200 Series PCL 5e"
EndIf


IniWrite ( $ini, "PRINTER QUE", "Printer", $printer )
IniWrite ( $ini, "PRINTER IP", "IP", $ip)
IniWrite ( $ini, "PRINTER DRIVERS", "Driver", $drv )
IniWrite ( $ini, "PRINTER DISCRIPTION", "Discription", $dis )
MsgBox( 64, "Ini Creation", $ini & " has been created successfully")

THE PRINTER CODE

#include <file.au3>
;Read INI File 
$que = IniRead( "printer.ini", "PRINTER QUE", "Printer", "")
$ip =  iniread("printer.ini", "PRINTER IP", "IP" ,"")
$driver =  IniRead( "printer.ini", "PRINTER DRIVERS", "Driver", "")
$description = IniRead("printer.ini", "PRINTER DISCRIPTION", "Discription","")

;Command string to run from INI file
$info = 'rundll32 printui.dll,PrintUIEntry /if /b ' & '"' & $que & '" /f "' & $driver & '" /r "' & "IP_" & $ip & '" /m "' &  $description & '" /z'

;Create *.vbs File From INI
_FileCreate(@TempDir & "\" & $que & ".vbs")

;name of the file to open
$file = @TempDir & "\" & $que & ".vbs"

$open = FileOpen($file, 0)
; Check if file opened for writing OK
If $open = -1 Then
    MsgBox(0, "Error", "Unable to open file from Temp directory.")

Else
FileWriteLine($file,'Set objWMIService = GetObject("winmgmts:")')
FileWriteLine($file, 'Set objNewPort = objWMIService.Get _')
FileWriteLine($file, '("Win32_TCPIPPrinterPort").SpawnInstance_')
FileWriteLine($file, 'objNewPort.Name = ' & '"IP_' & $ip & '"')
FileWriteLine($file, 'objNewPort.Protocol = 1')
FileWriteLine($file, 'objNewPort.HostAddress = ' & '"' & $ip & '"' )
FileWriteLine($file, 'objNewPort.PortNumber = "9100"')
FileWriteLine($file, 'objNewPort.SNMPEnabled = False')
FileWriteLine($file, 'objNewPort.Put_')

;Run Install
$destination = "sscreen.gif"
SplashImageOn("Installing printer " & $que, $destination, 272, 167,300,100,16)
RunWait(@ComSpec & " /c " & $file,"", @SW_HIDE)
RunWait(@ComSpec & " /c " & $info,"", @SW_HIDE)
Sleep(500)
SplashOff()
MsgBox(64,"Printer", "Printer has installed correctly")
Exit
EndIf

There is some more I want to do to this. I need some kind of error control to verify that the printer was installed correctly. Any ideas or thoughts on this would greatly be appreciated. Let me know if anyone has any questions.

Link to comment
Share on other sites

  • 3 years later...

Nice Idea folks..

It help much on my current projects... :)

[font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
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...