Solved

VBS to add a network printer and make it the default

Posted on 2011-03-05
2
714 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
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

770 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