Link to home
Start Free TrialLog in
Avatar of bwiser1
bwiser1Flag for United States of America

asked on

VBScript to add driver and printer locally

Hi, I have an issue with adding local printers. The script creates the port if it doesn't exist, then it should copy the driver from a local machine directory, then it should install the printer by IP to the machine. It seems I am having trouble getting the driver to copy over and install the printer when I tell it to reference the directory. I am not much of a VBScript guy, but am trying to pick up on it. Any help in resolving this would be much appreciated. FYI, the scripts I have made for the groups work great when the driver is already installed locally. Thanks for everyone's help in advance.

Please see my script below:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_169.1.1.221"
objNewPort.Protocol = 1
objNewPort.HostAddress = "IP_169.1.1.221"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = "HP LaserJet 2200 Series PCL"
objPrinter.PortName   = "IP_169.1.1.221"
objPrinter.DeviceID   = "Engineering"
objPrinter.Location = "Engineering"
objPrinter.Network = True
rem objPrinter.Shared = FALSE
rem objPrinter.ShareName = ""
objPrinter.Put_

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_169.1.1.220"
objNewPort.Protocol = 1
objNewPort.HostAddress = "169.1.1.220"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = "Canon iR C3080/3480/3580 PCL6"
objPrinter.PortName   = "IP_169.1.1.220"
objPrinter.DeviceID   = "1F Copier"
objPrinter.Location = "Sales"
objPrinter.Network = True
rem objPrinter.Shared = FALSE
rem objPrinter.ShareName = ""
objPrinter.Put_


I was told that to reference a print driver not in the .cab I could use this syntax below; but I am not sure how to tie this in. For our purposes here, let's reference a directory on the local machines on the root of C as so: C:\PrintDrivers\xxPrinterxx

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Set objDriver = objWMIService.Get("Win32_PrinterDriver")

objDriver.Name = "NewPrinter Model 2900"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriverPath = "C:\PrintDrivers\NewPrinter.dll"
objInfname = "C:\PrintDrivers\NewPrinter.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

Thanks again.
ASKER CERTIFIED SOLUTION
Avatar of Darren Collins
Darren Collins
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bwiser1

ASKER

This was exactly what I was looking for! Thank you.