Question : 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?

Thanks

Answer : Install network printer by script

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.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
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
Else
	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
 
	Next
	'Install Printers
	WSHNetwork.AddWindowsPrinterConnection strUNCToPrinter	
End If
Open in New Window Select All
Random Solutions  
 
programming4us programming4us