vb Script

I need a script which could do the following

Create a TCP/IP port for Printer xx.xx.xx.xx
Install a UPD PCL 6 driver
and give prompt once the driver is installed.

Thanks
thunder88Asked:
Who is Participating?
 
dax_badConnect With a Mentor Commented:
Hi Thunder88,

try this one
''   Script to automate TCP/IP printer installs ''

driverPath = "C:\Documents and Settings\xyz\My Documents\Downloads\upd-PCL6-X32-5_2_6_9321" 
        
driverInf = "C:\Documents and Settings\xyz\My Documents\Downloads\upd-PCL6-X32-5_2_6_9321\hpcu112c.inf" 
        
driverName = "HP LaserJet 4100 Series PS"

portName = "RM 206 HP4050"

portIP = "10.17.106.150"

printerLoc = "EHN RM219"

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, path, inf,location)

    objPrinter.DriverName = driver

    objDriver.DriverPath = path

    objDriver.Infname = inf

    objPrinter.PortName = port

    objPrinter.DeviceID = name

    objPrinter.Location = location

    objPrinter.Network = True

    objPrinter.Shared = false

    objPrinter.ShareName = ""

    objPrinter.Put_

end sub

createPort portName,portIP

addPrinter driverName,portName,portName,driverPath,driverInf,printerLoc

msgbox ("Printer installation complete.")

Open in new window

0
 
dax_badCommented:
try this script
''   Script to automate TCP/IP printer installs ''

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 = "EHN RM219"

    objPrinter.Network = True

    objPrinter.Shared = false

    objPrinter.ShareName = ""

    objPrinter.Put_

end sub

createPort "RM 206 HP4050", "10.17.106.150"

addPrinter "HP LaserJet 4100 Series PS","RM 206 HP4100","RM 206 HP4100"

msgbox ("Printer installation complete.  Don't Forget to make it the default printer")

Open in new window

0
 
thunder88Author Commented:
and where is it going to get the driver from...

please send me where can I add path to the driver.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
thunder88Author Commented:
I am trying the this script, but this only creates the port but doesn't install the driver can you please tell me what I am doing wrong in it.
On Error Resume Next 
 
'SETS 'LOAD DRIVER' PRIVILEGE. 
 
 
    Set objWMIService = GetObject("Winmgmts:") 
 
    objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
 
 
'SETS PRINTER PORT. 
 
 
    Set objNewPort = objWMIService.Get _ 
        ("Win32_TCPIPPrinterPort").SpawnInstance_ 
 
    objNewPort.Name = "IP_10.1.10.16" 
 
    objNewPort.Protocol = 1 
 
    objNewPort.HostAddress = "10.1.10.16" 
 
    objNewPort.PortNumber = "9100" 
 
    objNewPort.SNMPEnabled = False 
 
    objNewPort.Put_ 
 
 
'SETS PRINTER TO PORT. 
 
 
    strComputer = "." 
	Set objWMIService = GetObject("winmgmts:" _ 
		& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
	objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
 
	Set objDriver = objWMIService.Get("Win32_PrinterDriver") 
	set objShell = CreateObject("Wscript.Shell") 
 
    objDriver.Name = "HP Universal Printing PCL 6" 
	objDriver.SupportedPlatform = "Windows NT x86" 
	objDriver.Version = "3" 
 
    objPrinter.PortName   = "IP_10.1.10.16" 
 
    objPrinter.DeviceID   = "HPLaserJet_4350_Staff1" 
 
    objPrinter.Location = "Staff1" 
 
    objDriver.DriverPath = "C:\Documents and Settings\xyz\My Documents\Downloads\upd-PCL6-X32-5_2_6_9321" 
	
	objDriver.Infname = "C:\Documents and Settings\xyz\My Documents\Downloads\upd-PCL6-X32-5_2_6_9321\hpcu112c.inf" 
	
	intResult = objDriver.AddPrinterDriver(objDriver)

Open in new window

0
 
thunder88Author Commented:
I fixed it by my own
0
 
dax_badCommented:
well of course you have to download the drivers, put it on a local or network path and refer to that in the script.
0
 
thunder88Author Commented:
I have to work around by my own
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.