Solved

VBS to add a network printer and make it the default

Posted on 2011-03-05
2
726 Views
Last Modified: 2012-05-11
Can someone please tell me if this code looks good? It works but I wanted to make usre that there wasnt a better way to write it. Thank you.

Option Explicit
Dim objNetwork, strUNCPrinter
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection "\\printserver\printer"
strUNCPrinter = "\\printserver\printer"
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter
WScript.Quit

Open in new window


0
Comment
Question by:mkllpit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 250 total points
ID: 35044033
The code looks good
0
 
LVL 7

Assisted Solution

by:ednetman
ednetman earned 250 total points
ID: 35046350
Looks good, maybe add in some error handling like a line in the beginning:
On error resume next

This will keep the script from stopping with an error on the screen. Usefull for batch and silent installs.

And if there is an error, you could consider writing a file that shows you need to go back to that one. Maybe have SMS or Altiris look for the file and build a collection based on presence.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question