We help IT Professionals succeed at work.
Get Started

VBScript to add driver and printer locally

1,079 Views
Last Modified: 2012-05-11
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.
Comment
Watch Question
Tech Lead (Windows), Endpoint Device Management Services
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE