Home > Windows Server Tips > Windows Systems and Network Administration > How to use VBscript to add designated printers by machine name
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WINDOWS SYSTEMS AND NETWORK ADMINISTRATION

How to use VBscript to add designated printers by machine name


Andrew Robson
06.06.2007
Rating: -1.50- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Windows Systems and Network Administration
Cutting the cost of Windows identity and access management
Using NTFS on a non-Windows OS with NTFS-3G
Group Policy Object modeling simplifies network security
Implementing simple Network Access Protection for Windows Server 2008
Immediate steps for Windows disaster recovery
Tips for Windows domain controller optimization
Quick hits: Troubleshooting service account failure, batch job execution
Case Study: Troubleshooting Windows service dependency failures
Troubleshooting common Windows service failures
Reducing the size of network backups in Windows

Windows File Management
Using NTFS on a non-Windows OS with NTFS-3G
File classification the automated way with Windows Server 2008 R2
Using DFS to create file system virtualization in Windows Server 2008
File server migration tips for Windows Server 2008
Windows Distributed File System (DFS) Tutorial
Planning a file server migration to Windows 2008
Windows Distributed File System (DFS) Namespace primer
Self-healing NTFS keeps admins one step ahead of data corruption
Windows NTFS Tutorial
Windows registry hack improves offline file access for mobile users
Windows File Management Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
NTFS  (SearchWindowsServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


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

Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




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.



Server Room Design - Planning, Cooling, Maintenance
HomeTopicsBlogsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2004 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts