How to use VBscript to add designated printers by machine name

This user-submitted tip examines how admins can use VBscript to add designated printers by machine name.

This VBscript adds designated printers by machine name (Machines are named by room then number). It also adds a common printer and sets the closest printer as default.

Dim oNet, pcname
Set oNet = CreateObject("WScript.Network") pcname = UCase(oNet.ComputerName)

oNet.AddWindowsPrinterConnection "\serverLibrary Copier"

If InStr(1, pcname,"C35") > 0 Then
oNet.AddWindowsPrinterConnection "\serverC35 Printer"
oNet.SetDefaultPrinter "\serverC35 Printer"
End If

If InStr(1, pcname,"C36") > 0 Then
oNet.AddWindowsPrinterConnection "\serverC36 Printer"
oNet.SetDefaultPrinter "\serverC36 Printer"
End If

If InStr(1, pcname,"C37") > 0 Then
oNet.AddWindowsPrinterConnection "\serverC37 Printer"
oNet.SetDefaultPrinter "\serverC37 Printer"
End If

If InStr(1, pcname,"C38") > 0 Then
oNet.AddWindowsPrinterConnection "\serverC38 Printer"
oNet.SetDefaultPrinter "\serverC38 Printer"
End If

If InStr(1, pcname,"B13") > 0 Then
oNet.AddWindowsPrinterConnection "\serverB13 B&W Printer"
oNet.AddWindowsPrinterConnection "\serverB13 Color Printer"
oNet.SetDefaultPrinter "\serverB13 B&W Printer"
End If

If InStr(1, pcname,"B16") > 0 Then
oNet.AddWindowsPrinterConnection "\serverB16 B&W Printer"
oNet.AddWindowsPrinterConnection "\serverB16 Color Printer"
oNet.SetDefaultPrinter "\serverB16 B&W Printer"
End If

If InStr(1, pcname,"B18") > 0 Then
oNet.AddWindowsPrinterConnection "\serverB18 B&W Printer"
oNet.AddWindowsPrinterConnection "\serverB18 Color Printer"
oNet.SetDefaultPrinter "\serverB18 B&W Printer"
End If

If InStr(1, pcname,"B19") > 0 Then
oNet.AddWindowsPrinterConnection "\serverB19 B&W Printer"
oNet.AddWindowsPrinterConnection "\serverB19 Color Printer"
oNet.SetDefaultPrinter "\serverB19 B&W Printer"
End If

If InStr(1, pcname,"D24") > 0 Then
oNet.AddWindowsPrinterConnection "\serverD24 Printer"
oNet.SetDefaultPrinter "\serverD24 Printer"
End If

If InStr(1, pcname,"D27") > 0 Then
oNet.AddWindowsPrinterConnection "\serverD28 Printer"
oNet.SetDefaultPrinter "\serverD28 Printer"
End If

If InStr(1, pcname,"D28") > 0 Then
oNet.AddWindowsPrinterConnection "\serverD27 Printer"
oNet.SetDefaultPrinter "\serverD27 Printer"
End If

If InStr(1, pcname,"B2-999") > 0 Then
oNet.AddWindowsPrinterConnection "\serverD27 Printer"
oNet.SetDefaultPrinter "\serverD27 Printer"
End If

If InStr(1, pcname,"A1") > 0 Then
oNet.AddWindowsPrinterConnection "\serverA1 Printer"
oNet.SetDefaultPrinter "\serverA1 Printer"
End If

If InStr(1, pcname,"VCE") > 0 Then
oNet.AddWindowsPrinterConnection "\serverVCE Study Printer"
oNet.SetDefaultPrinter "\serverVCE Study Printer"
End If

If InStr(1, pcname,"WOOD") > 0 Then
oNet.AddWindowsPrinterConnection "\serverWoodwork Printer"
oNet.SetDefaultPrinter "\serverWoodwork Printer"
End If

If InStr(1, pcname,"MUSIC") > 0 Then
oNet.AddWindowsPrinterConnection "\serverH1 Printer"
oNet.SetDefaultPrinter "\serverH1 Printer"
End If

If InStr(1, pcname,"STUDENT") > 0 Then
oNet.AddWindowsPrinterConnection "\serverStudent Services Printer"
oNet.SetDefaultPrinter "\serverStudent Services Printer"
End If

If InStr(1, pcname,"LIBRARY-S") > 0 Then
oNet.AddWindowsPrinterConnection "\serverLib Area 1 Printer"
oNet.AddWindowsPrinterConnection "\serverLib Area 2 Printer"
oNet.SetDefaultPrinter "\serverLib Area 1 Printer"
End If

Rating this tip below will let us know how useful it was to you. And if you have a Windows tip, timesaver or workaround to share, submit it to our tip contest. You could win the prize for that contest.
This was first published in June 2007

Dig deeper on Windows File Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close