Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printer swap with script.. help!

Posted on 2009-07-07
2
Medium Priority
?
256 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

660 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