Solved

VBS to add a network printer and make it the default

Posted on 2011-03-05
2
695 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
2 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 250 total points
Comment Utility
The code looks good
0
 
LVL 7

Assisted Solution

by:ednetman
ednetman earned 250 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now