• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

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
0
thunder88
Asked:
thunder88
  • 4
  • 3
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dax_badCommented:
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now