Solved

Printer swap with script.. help!

Posted on 2009-07-07
2
250 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
[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 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

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

710 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