# Solved: batch file check for printer



## fox 2 (Nov 27, 2008)

Hi I am running a batch file to autmatically add a printer on login for all users, but my problem is that I need to know if the printer already exists before installing.


```
reg query 
HKCU\Printers\Connections
```
This shows me if the printer is installed and as there is only one printer on the network, I thought I would be able to compare this against the string. If it is equal then End if it is not equal then add the printer.

The problem I get is how to pass the result from the reg query to compare it against the string (location in reg of printer).

Adding the printer is not a problem using

```
REM Add Defualt Printer 
RunDll32.EXE printui.dll,PrintUIEntry /in /y /n [URL="file://\\servername\testprinter"]\\servername\testprinter[/URL] 
EXIT
```
Thanks for any help


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

I have a shared network printer (old HP 560C). The HKCU\Printers\Connections lists it as follows:

*,,ServerName,HP DeskJet 560C

* The following will search for the 560C in the registry and exit if it finds the above string. If it is not found, it will install the printer:


```
For /F "Tokens=4 delims=\" %%I In ('reg query HKCU\Printers\Connections ^|find /I "560C"') Do If "%%I"==",,ServerName,HP DeskJet 560C" Goto :EOF
REM Add Default Printer
RunDll32.EXE printui.dll,PrintUIEntry /in /y /n [URL="file://%5c%5cservername%5ctestprinter/"]\\servername\testprinter[/URL]
```
The Find search string needs to be specific enough so it only finds the one printer, so if you have the same printer on different servers you'd need to use the entire string in the Find command.

HTH

Jerry


----------



## fox 2 (Nov 27, 2008)

Nice one!

tried it and it works like a dream! thank you very much, I didn't know about the Find command


----------



## TheOutcaste (Aug 8, 2007)

You're Welcome!

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post) 










Jerry


----------

