Deploying Printers via VBS

I have created a VBS script to add network printers to a specific group of users within a OU.

This has been in place for about 3 months now, and initially since I was changing to new servers, i had to delete all the old printers and add the new ones, hence why i made a scrip to add the new printers. The vbs is deployed through a GPO. That GPO is still enabled. What I dont understand is there is no default printer setting in the vbs, but randomly some machines default printer will change to the first printer on the vbs.

Help please?
Who is Participating?
BlackAdderDKConnect With a Mentor Commented:

I'm not sure what's the problem... the fact that you have default printer... or the fact that it's the wrong one...

Case "Wrong One"

The following sets your printer as default printer

Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "<PrinterName>"

and if it's an Network shared printer

Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\<ServerName>\>PrinterName>"
Case "Don't Want One"

That's a problem... as far as I remember, Windows insists on having a default printer - but you could cheat a little... and set the default printer to MS XPS Document Writer (I suppose you have that)

Option Explicit
 Dim objPrinter
 Set objPrinter = CreateObject("WScript.Network")
 objPrinter.SetDefaultPrinter "Microsoft XPS Document Writer"

merowingerConnect With a Mentor Commented:
here's a script to only set the default printer if it exists
strPrinter = "\\PrinterServer\DefaultPrinter"

set objNet=Createobject("wscript.Network")
set objPrinters=objNet.EnumPrinterConnections


For i=0 to objPrinters.count-1
	If Instr(objPrinters.Item(i),strPrinter) Then
		Exit For
	End If

If bolPrinterExists Then
		objPrinter.SetDefaultPrinter strPrinter
End If

Open in new window

mt3dekAuthor Commented:
There are about 20 printers in this script and its set to a OU with about 30 users. They all dont have the same default printer and thats why i didnt specify one in the script. Ive manually gone to each users PC after the script ran and added the printers and changed the default printer. The thing that is not connecting for me, is why intermittently does the default change when i dont have a default specified in the script but have a default set already in windows.

Does this make sense?
Option Explicit
Dim objNetwork, strLocal, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4, strUNCPrinter5, strUNCPrinter6, strUNCPrinter7, strUNCPrinter8, strUNCPrinter9, strUNCPrinter10, strUNCPrinter11
strUNCPrinter1 = "\\BPBAK\BAKAA2"
strUNCPrinter2 = "\\BPBAK\BAKAA3"
strUNCPrinter3 = "\\BPBAK\BAKAA4"
strUNCPrinter4 = "\\BPBAK\BAKATTY"
strUNCPrinter5 = "\\BPBAK\BAKCF"
strUNCPrinter6 = "\\BPBAK\BAKGFM"
strUNCPrinter7 = "\\BPBAK\BAKLIB"
strUNCPrinter8 = "\\BPBAK\BAKOA"
strUNCPrinter9 = "\\BPBAK\BAKWP1"
strUNCPrinter10 = "\\BPBAK\BAKiR5065-1"
strUNCPrinter11 = "\\BPBAK\BAKiR5065-2"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
objNetwork.AddWindowsPrinterConnection strUNCPrinter3
objNetwork.AddWindowsPrinterConnection strUNCPrinter4
objNetwork.AddWindowsPrinterConnection strUNCPrinter5
objNetwork.AddWindowsPrinterConnection strUNCPrinter6
objNetwork.AddWindowsPrinterConnection strUNCPrinter7
objNetwork.AddWindowsPrinterConnection strUNCPrinter8
objNetwork.AddWindowsPrinterConnection strUNCPrinter9
objNetwork.AddWindowsPrinterConnection strUNCPrinter10
objNetwork.AddWindowsPrinterConnection strUNCPrinter11


Open in new window

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

merowingerConnect With a Mentor Commented:
I think the last one which is added will be automatically to the default printer.
Why won't you add a query into the script which configures the default printer based on the username?!

set objNet = CreateObject("Wscript.Network")
strUsername = objNet.UserName

Select Case (strUsername)
Case "John"
    objPrinter.SetDefaultPrinter strUNCPrinter7
Case "Jack"
    objPrinter.SetDefaultPrinter strUNCPrinter3
Case "Emma"
    objPrinter.SetDefaultPrinter strUNCPrinter2
Case Else
End Select
mt3dekAuthor Commented:
i didnt know i could specify a default to a username.
The whole purpose of using a printer script is so i dont have to remember to go add printers to a new employees local profile on their machine.
You can also query groups in active directory. So if a new employees joins the company you create the user and make it member of a specific ad group. When it logs on the script will automatically set the correct default printer
mt3dekAuthor Commented:
If i already have a default set, is there a line that can be included to not set the default printer or not to modify default printers if there is already a default?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
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.

All Courses

From novice to tech pro — start learning today.