Solved

VBS to add a network printer and make it the default

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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