Microsoft:Printing:Script Install

From My Notepad
Jump to: navigation, search

Scripting a printer install

''----------------------------------------------''
''----------------------------------------------''
''                                              ''
''   Script to automate TCP/IP printer installs '' 
''       (Andrew Levine - 12/2004)              ''
''                                              ''
''----------------------------------------------''
''----------------------------------------------''

Set WSHNetwork = WScript.CreateObject("WScript.Network")
set shell = WScript.CreateObject( "WScript.Shell" )
CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set oShell = WScript.CreateObject("WScript.shell")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

sub createPort (name, ip)
    objNewPort.Name = name
    objNewPort.Protocol = 1
    objNewPort.HostAddress = ip
    objNewPort.SNMPEnabled = False
    objNewPort.Put_
end sub

sub addPrinter (driver, port, name)
    objPrinter.DriverName = driver
    objPrinter.PortName = port
    objPrinter.DeviceID = name
    objPrinter.Location = "CEH"
    objPrinter.Network = True
    objPrinter.Shared = false
    objPrinter.ShareName = ""
    objPrinter.Put_ 
end sub

'------------------'
'Add printer ports:'
'------------------'
createPort "IP_192.168.1.202", "192.168.1.202"

'----------------------------------------------'
'Install printers with drivers native to WinXP:'
'----------------------------------------------'
'                                                TCP/IP Port Name        Display Name
'                                                --------------------    -----------------
'addPrinter "HP Color LaserJet 8500 PS",        "HP8500_Exec_color",     "HP8500 Color PS"
'addPrinter "HP LaserJet 4200 PS",              "HP4200_BCEHFP_North",   "HP4200 North PS"
'addPrinter "HP LaserJet 4200 PCL 6",           "HP4200_BCEHFP_North",   "HP4200 North"

'-------------------------------------------------' Display name
'Install printers with externally defined drivers:' for printer   Driver location     Port name     Driver name in .inf file
'-------------------------------------------------' -----------   ---------------     ---------     ------------------------
oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LaserJet 5200 PCL 6"" /f G:\Drivers\Printers\HPLaserJet5200\PCL6\hpc5200c.inf /r ""IP_192.168.1.202"" /m ""HP LaserJet 5200 PCL 6"""     ,,true

msgbox ("Printer installation complete.")