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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.


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"


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
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

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

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.
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.