Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HP 2035 Local USB install script

Posted on 2011-09-14
4
Medium Priority
?
1,452 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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 …
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

971 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