Solved

HP 2035 Local USB install script

Posted on 2011-09-14
4
1,375 Views
Last Modified: 2012-05-12
I'm trying to create a script to automatically install an HP2035 to on a user PC that has the printer plugged into the USB port.

So far, this is what I've come up with, but it's not working as intended.
 It looks like it copies the drivers from the network drive to the user PC, but it never creates the printer in the Printers and Faxes window.

Here's a link to the INF file I'm using: http://driveragent.com/0/archive/37877/1-0-9?q=hp2030.inf+%2Fmodel
strComputer = "."
Set oShell = WScript.CreateObject("WScript.shell")
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
 
Set objDriver = objWMIService.Get("Win32_PrinterDriver") 
 
objDriver.Name = "HP LaserJet P2035" 
objDriver.SupportedPlatform = "Windows NT x86" 
objDriver.Version = "3" 
objDriver.DriverPath = "I:\Scripts\P2035\" 
objDriver.Infname = "I:\Scripts\P2035\HP2030.INF"
intResult = objDriver.AddPrinterDriver(objDriver)

oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LaserJet P2035"" /f I:\Scripts\P2035\HP2030.INF /r ""usb001:"" /m ""HP LaserJet P2035""" ,,true

msgbox ("Printer installation complete.")

Open in new window

0
Comment
Question by:Wiretwisterz
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36540412
Have you tried using something like this:
strPrinterName = "HP LaserJet P2035"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
 
Set objDriver = objWMIService.Get("Win32_PrinterDriver") 
 
objDriver.Name = strPrinterName 
objDriver.SupportedPlatform = "Windows NT x86" 
objDriver.Version = "3" 
objDriver.DriverPath = "I:\Scripts\P2035\" 
objDriver.Infname = "I:\Scripts\P2035\HP2030.INF"
intResult = objDriver.AddPrinterDriver(objDriver)

objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.Name = strPrinterName
objPrinter.DriverName = strPrinterName
objPrinter.PortName = "usb001"
objPrinter.DeviceID = strPrinterName
objPrinter.Network = False
objPrinter.Shared = False
objPrinter.Put_()

Open in new window

0
 
LVL 1

Author Comment

by:Wiretwisterz
ID: 36542317
I made two small additions to the script, but yes it worked like a charm.  

I added the strComputer = "." at the top, and I added the "Set" at the beginning of objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_


Below is the final code, thanks for the help.
strComputer = "."
strPrinterName = "HP LaserJet P2035"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
 
Set objDriver = objWMIService.Get("Win32_PrinterDriver") 
 
objDriver.Name = strPrinterName 
objDriver.SupportedPlatform = "Windows NT x86" 
objDriver.Version = "3" 
objDriver.DriverPath = "I:\Scripts\P2035\" 
objDriver.Infname = "I:\Scripts\P2035\HP2030.INF"
intResult = objDriver.AddPrinterDriver(objDriver)

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.Name = strPrinterName
objPrinter.DriverName = strPrinterName
objPrinter.PortName = "usb001"
objPrinter.DeviceID = strPrinterName
objPrinter.Network = False
objPrinter.Shared = False
objPrinter.Put_() 

msgbox ("Printer installation complete.")

Set colInstalledPrinters =  objWMIService.ExecQuery _
("Select * from Win32_Printer where Default = 'True'")


	For Each objPrinter in colInstalledPrinters
	Wscript.Echo "Your current default printer is: " & objPrinter.Name
	Next 

intAnswer = Msgbox("Do you want to make the HP Laserjet P2035 your default printer?"  , vbYesNo, "Make default Printer?")


	If intAnswer = vbYes Then

		strComputer = "."

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


		Set colInstalledPrinters =  objWMIService.ExecQuery _
		("Select * from Win32_Printer Where Name = 'HP LaserJet P2035'")

		For Each objPrinter in colInstalledPrinters
		objPrinter.SetDefaultPrinter()
		Next 

	End If

Open in new window

0
 
LVL 1

Author Closing Comment

by:Wiretwisterz
ID: 36542325
Thanks for the help!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36542388
Oh yeah, I missed those somehow....well spotted though!

I'm glad it worked!

Rob.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question