Install network printer by script

I want to create a script, preferably in vbs to check if a printer is installed, and if not install the printer.
Ive tried using the rundll32 printui.dll, PrintUIEntry command, but I dont think this command includes a way to check if the printer is already installed.
The script will be added to a users logon.
Does anyone have any examples?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If it is a network printer, you can use the following.  This will add a printer once only, so when a user first logs on, they get the printer connected.  If you add the printers each time they log on, they will lose any custom settings for paper sizes etc.

Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("WScript.Shell")
blnPrinterSet = False
strPrinterSet = wshSHell.RegRead("HKCU\Software\LoginScript\PrinterSet")
If Len(strPrinterSet) > 0 Then
	blnPrinterSet = True
	wshShell.RegWrite "HKCU\Software\LoginScript\PrinterSet", "1"
End If
If not blnPrinterSet Then
	'Remove ALL old printers
	'Enumerate all printers first, after that you can select the printers you want by performing some string checks
	Set WSHPrinters = WSHNetwork.EnumPrinterConnections
	For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
	'To remove only networked printers use this If Statement
	    If Left(WSHPrinters.Item(LOOP_COUNTER + 1), 2) = "\\" Then
		If WSHPrinters.Item(LOOP_COUNTER + 1) <> "" then
	     		WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER + 1), True, True
		End IF
	    End If
	'Install Printers
	WSHNetwork.AddWindowsPrinterConnection strUNCToPrinter	
End If

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITSUPPORT2Author Commented:
So as I understand it, this script can be run every time the user logs on and won't overwrite the users custom printer settings


Thats correct.  The registry flag tells the script that the user has already had printers mapped, so won't do it again and overwrite all their settings.
ITSUPPORT2Author Commented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.