Solved

HP 2035 Local USB install script

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

10 Experts available now in Live!

Get 1:1 Help Now