Solved

HP 2035 Local USB install script

Posted on 2011-09-14
4
1,354 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now