Batchfile Question

Associate
Joined
22 Dec 2002
Posts
1,190
Location
Teesside, UK
currently have a batch file to delete a printer on login. This refers to the 'Microsoft Document Image Writer'. The only problem I have is if the printer has already been moved the batch file complains with an error that the printer cannot be found.

Is there a command or something can add so that it can check and ignore if the printer has already been removed, or at least not show any errors to the user.

Here is the batch file contents;
rundll32 printui.dll,PrintUIEntry /dl /n "Microsoft Document Image Writer"

Thanks,
andy
 
not the cleanest way to do it, but you could tell it to make a directory, like C:\windows\done

md %windir%\done


after it's done the printer, then in the bat before the delete section, you could put "if exist %windir%\done goto end"

after the script, put ":end"

then it'll jump over the script

been a while since i messed with printers in bat files
 
Thanks for replying.

If the printer is re-installed at any point. Say through an Office update or windows update would it not still skip the removal of the printer.

Having said that now that you have hit on the IF command, I'm wondering if there is a way for the PC to check if the Printer is installed. Kind of if it is run this command. If not don't
 
Rather than trying to work out if the printer is there it'll be easier just to suppress the error generated if it's not there.

Redirecting the command to null should do it.
 
Sorry my batch file experience is fairly limited. Is that just a case of putting null at the end. I'm not at work at the moment to further test.
 
Sorry my batch file experience is fairly limited. Is that just a case of putting null at the end. I'm not at work at the moment to further test.

rundll32 printui.dll,PrintUIEntry /dl /n "Microsoft Document Image Writer" > null

You can also use the same technique to save the output of batchs to text files. Can be very handy.
 
You might need to use:

2> nul

the above will redirect standard error to nul or if the command is untidy and doesn't use standard error then

> nul 2>&1

which will redirect standard out and error to nul
 
Thanks for your replies.

Tried 2> nul and > nul 2>&1, but the error of not finding the printer still pops up. Any further suggestions much appreciated.

Edit. I may have solved this myself by including the /q command.
 
Last edited:
sorry to keep questioning this. All is working great, but there is one slight problem. The users dont have permissions to remove the printer, so the logon script appears to miss this part.

Is it possible to include a line in the script to use the Run As feature.
 
You can actually supply the password in the runas but then it's viewable for everyone to see (so if you used a local admin account then the username and password would be available to anyone to see and use).

I know if you remove the printer as an administrator it doesn't come back but if you have it out in the field on hundreds of machines it's pointless going through it.

Perhaps scheduling you batch file may be better as you can give the credentials in there?


M.
 
Back
Top Bottom