Solved

Printer swap with script.. help!

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 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