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.
VB ScriptWindows XPPrinters and Scanners

Avatar of undefined
Last Comment
bwiser1
ASKER CERTIFIED SOLUTION
Avatar of Darren Collins
Darren Collins
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of bwiser1
bwiser1
Flag of United States of America image

ASKER

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

Microsoft Windows XP is the sixth release of the NT series of operating systems, and was the first to be marketed in a variety of editions: XP Home and XP Professional, designed for business and power users. The advanced features in XP Professional are generally disabled in Home Edition, but are there and can be activated. There were two 64-bit editions, an embedded edition and a tablet edition.

119K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo