Solved

Batch Script Help Needed

Posted on 2010-09-23
3
314 Views
Last Modified: 2012-05-10
I am trying to run a command using a Batch file script to change a printer name if it exists.  Here's the rundown of the PseudoCode I am trying to accomplish.

If "Zebra LP2844" Printer name exists
  Change printer name to ComputerName_LP2844
Else
   END/Do Nothing

Now the command to change the printer name is:
     rundll32 PrintuUI.DLL,PrintUIEntry /XS /n "Zebra LP2844" PrinterName "%COMPUTERNAME%_LP2844"

This however assumes there is a printer specifically named "Zebra LP2844" otherwise it gives an error, which is something I need it to not do.  I thought an IF statement would be best but a try catch would be fine to handle the error, it doesn't matter so long as the end user never sees the error and the printer name is changed if it is incorrect.  Thanks.
0
Comment
Question by:PhillipsPlastics
[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
3 Comments
 
LVL 1

Expert Comment

by:stupsnose
ID: 33747801
You cannot do what you want. Because you pass the printername to rundll, the error is thrown by rundll, i think as a messagebox. You cannnot hide that from commandline
0
 
LVL 14

Accepted Solution

by:
Erik Pitti earned 500 total points
ID: 33747896
This script will query for installed printers and rename the one that matches OLD_PRINTER_NAME to the value of NEW_PRINTER_NAME
@ECHO OFF
SETLOCAL

SET OLD_PRINTER_NAME="Zebra LP2844"
SET NEW_PRINTER_NAME="%COMPUTERNAME%_LP2844"

SET REGPATH=HKLM\System\CurrentControlSet\Control\Print\Printers

FOR /F "tokens=6* delims=\" %%A in ('reg query %REGPATH%') DO (
	IF "%%B" EQU %OLD_PRINTER_NAME% (
		rundll32 PrintuUI.DLL,PrintUIEntry /XS /n %OLD_PRINTER_NAME% PrinterName %NEW_PRINTER_NAME%
	)
)

ENDLOCAL

Open in new window

0
 

Author Comment

by:PhillipsPlastics
ID: 33748200
@ECHO OFF
SETLOCAL

SET OLD_PRINTER_NAME="Zebra LP2844"
SET NEW_PRINTER_NAME="%COMPUTERNAME%_LP2844"

SET REGPATH=HKLM\System\CurrentControlSet\Control\Print\Printers

FOR /F "tokens=6* delims=\" %%A in ('reg query %REGPATH%') DO (
      IF "%%B" EQU %OLD_PRINTER_NAME% (
            rundll32 PRINTUI.DLL,PrintUIEntry /Xs /n %OLD_PRINTER_NAME% PrinterName %NEW_PRINTER_NAME%
      )
)

ENDLOCAL

That was awesome works great thanks for the help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

617 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