Batch File Scripting/setting printers

February 15, 2011 at 06:44:56
Specs: Windows XP
I am writing a batch script to update about 300 offsite Windows XP systems. I am resetting various printer information and downloading new drivers. At one point, I need to check whether their default printer is set as a particular printer (Zebra Printer) and if so, I have to set it to the new option (Zebra Label Printer) so that it will use the new driver. So within the batch script, I call another script which consists of

@echo off
setLocal EnableDelayedExpansion

REM Skip the first 3 lines, then assign the 4th line to a variable.
for /f "tokens=* skip=3 delims= " %%a in (c:\temp\default-printer.txt) do (
if !myvar!'==' set myvar=%%a

REM Replace the "The default printer is" phrase with all blanks.
set myvar=%myvar:The default printer is= %

REM Now left trim the variable
for /f "tokens=* delims= " %%a in ("%myvar%") do set myvar=%%a

IF !myvar! == "Zebra Printer" rundll32 printui.dll,PrintUIEntry /y /n "Zebra Label Printer"

REM And output the result.
echo !myvar!

That last line is just a way for me to test this script at the command line to make sure it is pulling the correct information. The problem I am running into is my last IF statement - the rundll32 entry which sets the new default printer - it is not running that command. If I run that whole command (rundll32 printui.dll,PrintUIEntry /y /n "Zebra Label Printer") at the command line, it works fine, but it is not working within the batch script. Do I enclose it in quotes. brackets, something else?

Any help would be appreciated, thank you!

See More: Batch File Scripting/setting printers

Report •

February 15, 2011 at 07:53:36
there are other things I find questionable in your code but the folliowing should be the key point

if "!myvar!"=="Zebra Printer" rundll32 printui.dll,PrintUIEntry /y /n "Zebra Label Printer"

Report •

February 15, 2011 at 08:51:18
Yes - that is the line that I cannot get to work. The code prior to that is simply to get just the default printer name out of the 4 lines that result from

script prnmngr.vbs - g

which I've dumped into default-printer.txt. I then just need to check whether they have a "Zebra Printer" as their default. If so, I need to change it to "Zebra Label Printer" which uses a new driver. However, that IF statement is not working.

Report •

February 15, 2011 at 09:02:36
Did you try what I posted?

Your line will never work as you cided it.

Report •

Related Solutions

February 15, 2011 at 09:30:27
Thank you - I had not noticed any difference - it took me a minute to see the quotes around !myvar! . I thought you had simply highlighted that line to verify that was the line of code I was talking about.

Report •

Ask Question