Solved

Printer swap with script.. help!

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

735 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