Tip

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

Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.