Solved

HP 2035 Local USB install script

Posted on 2011-09-14
4
1,394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 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