troubleshooting Question

VBScript to add driver and printer locally

Avatar of bwiser1
bwiser1Flag for United States of America asked on
VB ScriptWindows XPPrinters and Scanners
2 Comments1 Solution1084 ViewsLast Modified:
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
Darren Collins
Tech Lead (Windows), Endpoint Device Management Services

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros