Install network printer by script

Posted on 2009-05-20
Medium Priority
Last Modified: 2013-11-10
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?

Question by:ITSUPPORT2
  • 2
  • 2

Accepted Solution

johnny_the_knife earned 1000 total points
ID: 24437674
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


Author Comment

ID: 24438133
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



Expert Comment

ID: 24438936
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.

Author Closing Comment

ID: 31583786
Thank you

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
AngularJS web development a very simple procedure. So, to put it, in short, AngularJS’ stand out features are – Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

624 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