Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic installation of "local" printer 2

Status
Not open for further replies.

dparrott

MIS
Jul 26, 2004
201
US
Hey all,

I need to add a printer to about 100 machines. The printer is attached to the network using a print server (not a computer with the printer shared), and when we install the printer currently, it shows up with as a local printer, with the port being a raw data port with an IP address.

The clients do not have the driver already installed on their computers, but it is in an accessible network location. Most of the computers don't have the port installed either.

My guess, and this is only a guess, is that I will need a script that creates the port, uses the .inf file located on the network to install the driver, and then create the printer using that driver and setting the port to the recently created printer port. Does this sound like something that can be done? As long as it doesn't require installation of some runtime (so .vbs is fine, because support is already included), I would greatly appreciate any help in either pointing me to somewhere that this has been covered or in helping me out with the basics of a script (please note, I do not have much of a background using .vbs, so please forgive any ignorant questions I may have about it).

Thanks in advance,

Danny
 
Oh, by the way, the clients are all Windows XP Pro SP2. The driver is on a windows share, and the print server is an HP 170x print server
 
Not a lot of help here, but at least I tried.

You could try the VBscript forum.

This thread talks about the PrintUI command, whether it is of use or not is up to you I guess?
Thread779-581142

Changing a User's Default Printer in the Registry

Q310516 HOW TO: Distribute Registry Changes to Computers in Windows XP


See if this paragraph in the next old MSKB is of any help to the actual setup, if required?

"Printing to a Network Device"

Troubleshooting Printing Problems in Windows
 
dparrot

linney suggested this thread may help in relation to resolving thread779-1435936, and maybe I might be able help with your problem here.

dparrot said:
...is that I will need a script that creates the port, uses the .inf file located on the network to install the driver, and then create the printer using that driver and setting the port to the recently created printer port.

Suggest you google for the rktools.exe download from Microsoft.

In it you will find documentation for the use of prnadmin.dll.

This allows you to programatically add a new port and then programatically add a printer utilising the newly added port.

This might take you towards your goal as outlined above.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
I wrote a script a few years ago to automate IP Printer installs.

It's very long, and has a few menu's in it (a menu for each department), but i cut one section out and included my comments on top. Hope it helps

Code:
''----------------------------------------------''
''----------------------------------------------''
''											    ''
''   Script to automate TCP/IP printer installs '' 
''       (A.Levine - 12/2004)                     ''
''											    ''
''----------------------------------------------''
''----------------------------------------------''
''
'' 
'' Adding a printer has 3 steps:
''
''  1) Create a port:
''				Port Name	   Port IP  
''                      --------------------   --------------
''          createPort "HP4200_BCEHFP_North", "192.168.50.2"
''
''	2) Add the printer:
''          
''		Using drivers included in WinXP:
''						   XP Printer Name
'' 						   (Must be EXACT)        Port Name              Display Name
''						   -------------------	  --------------------   ---------------
''					addPrinter "HP LaserJet 4200 PS","HP4200_BCEHFP_North", "HP4200 North PS"
''
''		Using external drivers:
''											 Printer Name in INF File
''									 						Display Name         Location of INF file                   Port Name                  (Must be EXACT)
''															------------         -------------------------------        --------------------       ----------------------
''				oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP8150 South""    /f U:\instalxp\hp8150\HP8150_6.INF   /r ""HP8150_BCEHFP_South"" /m ""HP LaserJet 8150 PCL 6"""  ,,true
''
''  3) Load settings from DAT file:
''
''																	   Display Name         Location of DAT File
''																	   ------------         ------------------------------------------------
''				oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n ""HP8150 South""  /a ""u:\instalxp\PrinterScripts\BCEHFP\DAT\HP8150.dat""  d",,true
''
''
''
''
''  To create a DAT File:
''				
''			1) Install a printer on a local machine, and set any applicable options (memory, trays,duplexer, etc.)
''
''			2) Run the following command from a command line 
''			   This is very similar to the command to load settings from DAT file. 
''			   The only difference is that /Sr (settings restore) is replaced with /Ss (settings save)
''																	   Display Name         Location to save DAT File
''																	   ------------         ------------------------------------------------
''				oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /Ss /n ""HP8150 South""  /a ""u:\instalxp\PrinterScripts\BCEHFP\DAT\HP8150.dat""  d",,true
''
''
''
''--------------------------------------------------------------------------------------------------------------


Set WSHNetwork 		= WScript.CreateObject("WScript.Network")
set shell 		= WScript.CreateObject( "WScript.Shell" )
CompName 		= shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService 	= GetObject("winmgmts:\\" & CompName & "\root\cimv2")
Set objNewPort 		= objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set oShell 		= WScript.CreateObject("WScript.shell")
Set objPrinter 		= objWMIService.Get("Win32_Printer").SpawnInstance_

sub createPort (name, ip)
	objNewPort.Name 	= name
	objNewPort.Protocol 	= 1
	objNewPort.HostAddress 	= ip
	objNewPort.SNMPEnabled 	= False
	objNewPort.Put_
end sub

sub addPrinter (driver, port, name)
	objPrinter.DriverName 	= driver
	objPrinter.PortName 	= port
	objPrinter.DeviceID 	= name
	objPrinter.Location 	= "CEH"
	objPrinter.Network 	= True
	objPrinter.Shared 	= false
	objPrinter.ShareName 	= ""
	objPrinter.Put_ 
end sub

'-----------------'
'  IS&T Functions '
'-----------------'
	sub HP9000_IST
		createPort "HP9000_IST", "192.168.5.68"
		oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP9000 IS&T""    /f U:\instalxp\hp9000\hpbf512i.inf   /r ""HP9000_IST"" /m ""HP LaserJet 9000 PCL 6""" ,,true
		oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP9000 IS&T PS"" /f U:\instalxp\hp9000ps\hp9000ps.inf /r ""HP9000_IST"" /m ""HP LaserJet 9000 PS""" ,,true
		oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n ""HP9000 IS&T""    /a ""u:\instalxp\PrinterScripts\IS&T\DAT\HP9000 IS&T PCL.dat"" d" ,,true
		oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n ""HP9000 IS&T PS"" /a ""u:\instalxp\PrinterScripts\IS&T\DAT\HP9000 IS&T PS.dat""  d" ,,true
	end sub


	'-----------'
	' IS&T Menu '
	'-----------'
	sub menuIST
		message = "Please type the number of the printer to install:" 	& vbCrLf & _
				"(Press cancel or leave blank to quit.)" 	& vbCrLf & vbCrLf & _
				"1 - All Printers"  				& vbCrLf & vbCrLf &  _
				"2 - HP9000" 					& vbCrLf & _
				"3 - HP4500 Color in BTSA" 			& vbCrLf & _
				"4 - HP8550 Color in BEEI"			& vbCrLf & vbCrLf &_
				"0 - Back to main menu" 			& vbCrLf &_
				vbCrLf & vbCrLf & "Please enter a number:"
		
		title = "Install Printers - IS&T"


		do
			userInput = InputBox(message, title)
			select case userInput
				case "1"
					HP9000_IST
				case "0"
				case ""
					WScript.Quit
				case else
					msgbox "Invalid entry. Please try again."
			end select
			 loop while userInput <> "" and userInput <> "0"
	end sub	

'////////////////////////////////////////////////////////////////////////////////////////////////



menuISTU



Thanks,
Andrew
 
Nice!

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 

Is the data in the '.dat' file referred to in the excellent code posted by acl03, the same as the registry value:-

HKLM\SOFTWARE\Microsoft\WindowsNT\Print\Printers\PrinterName\PrinterDriverData\PrinterData ?

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris -

I don't think so. Those reg keys look like generic windows settings having to do with the printer. The .dat files I create with my script contain settings that are much more specific to your printer drivers.

One other thing - I never figured this one out: If you have two HP8150s with the same settings, you need to create separate dat files for each. The dat files (That extention .dat is made up by the way, it can be anything) must contain some really specific info.

let me know if you have any questions.



Thanks,
Andrew
 
Oh and I should note that the code I posted is partially borrowed from other users (I don't remember who, sadly) on these forums a few years ago. So credit goes to them too :)





Thanks,
Andrew
 
Well I've only tried this under Windows XP pro...I don't think the oshell commands that are used to install the printers work in 2000.

I would think that the dat files are probably XP/2003 only....that's only a guess though.



Thanks,
Andrew
 
acl03 said:
I don't think the oshell commands that are used to install the printers work in 2000.
Fortunately prnadmin.dll mentioned earlier will work with Win2K.

Found that using a modified version of
Code:
"RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n ""HP9000 IS&T PS"" /a ""u:\instalxp\PrinterScripts\IS&T\DAT\HP9000 IS&T PS.dat""  d" ,,true
as parameters to the WinAPI call ShellExecute will set the printer properties as required.

As far as a generic .dat file is concerned, there seems to be only one way to find out...[smile]

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
First create a suitable object from previously registered prnadmin.dll
Code:
oMaster = CREATEOBJECT([PrintMaster.PrintMaster.1])
This code is in VFP but should easily convert to other languages.

Omitting error trapping code etc, next add a port
Code:
oPort 	= CREATEOBJECT([Port.Port.1])

oPort.ServerName	= []
oPort.PortName		= 		;
	oMainObject.cHomeFolder	;
	+ [Output\output.ps]
oPort.PortType		= 3
oMaster.PortAdd(oPort)
Finally add a printer, ('&& text' are comments)
Code:
oPrinter 	= CREATEOBJECT([Printer.Printer.1])
		
oPrinter.ServerName		= []					&& Local machine
oPrinter.PrinterName	= [Myprinter]				&& Printer name
oPrinter.DriverName 	= [Ghostscript PDF]		&& Driver name
oPrinter.PortName		= 		;
			oMainObject.cHomeFolder		;
			+ [Output\output.ps]						&& Output filename
oPrinter.InfFile		= ADDBS(oMainObject.cHomeFolder)	;
								+ [bin\gs8.61\lib\ghostpdf.inf]	&& Inf file
oMaster.PrinterAdd(oPrinter)					&& Try to add the printer
oMaster.PrinterGet([],[Myprinter],oPrinter)		&& Get the added printer
oPrinter.Comment	= [Optimized by Me!]		&& Create comment
oMaster.PrinterSet(oPrinter)					&& Post data to printer
That should give you the general idea, specifics can be found in the documentation [smile]

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
acl03 said:
How'd it work on Win2k?
Apologies - just realised what you meant.


I read it that you were asking about adding a port/printer to a Win2K box rather than whether if the .dat files are generic.

Have yet to try it but will advise result when it's done.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris, no worries - that's good to know anyway :)



Thanks,
Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top