Solved

Printer swap with script.. help!

Posted on 2009-07-07
2
244 Views
Last Modified: 2013-11-09
We are changing out our main printer with a new model completely and I would like to write a script to change the default printer to the new printer only if the printer that is being swapping out is set as their default printer.  We have about 6 or 7 printers, but the main one is going and not everyone has that set to as their default.  The printer will be installed on our print server that is running server 2003.  Currently, we have one main login script and I was planning on just putting a string in there to map the new printer, but once the old one is gone I'm going to see all kinds of IT tickets wanting to know where their default printer went!  I'd like to avoid this if I can!!
0
Comment
Question by:michoo
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 24798627
Paste the script below into a text file with a .vbs extension.  Customize the value of the strOldPrinter variable on line 1 with the UNC path of the old printer.  Customize the value of the strNewPrinter variable on line 2 with the UNC path of the new printer.

Running the script will check the current default printer and, if it is set to the old one, will change it to the new one.  Otherwise it will leave it unchanged.


strOldPrinter = "\\server\oldprinter"

strNewPrinter = "\\server\newprinter"
 

On Error Resume Next
 

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colPrinters = objWMIService.ExecQuery _

    ("Select * From Win32_Printer Where Default = True")
 

For Each objPrinter in colPrinters

    If LCase(objPrinter.Caption) = LCase(strOldPrinter) Then

        Set objNetwork = CreateObject("Wscript.Network")

        objNetwork.SetDefaultPrinter strNewPrinter

    End If

Next

Open in new window

0
 

Author Closing Comment

by:michoo
ID: 31600817
Worked like a champ, thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

20 Experts available now in Live!

Get 1:1 Help Now