I’m creating a batch file to detect if a local printer has been installed and if it hasn’t other code will run.
For /F "Tokens=1 delims=" %%I In ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" ^|find /I "WPL"') Do If "%%I"=="Printer WPL-606" Goto :EOF
REM Otherwise Do Stuff
The result I’m getting when I run this is:
C:\Documents and Settings\kalamane>If ” Printer
WPL-606 REG_SZ winspool,Ne07:” == “Printer WPL-606” Goto :EOFC:\Documents and Settings\kalamane>REM Otherwise Do Stuff
Clearly the rest of the line from that registry entry is included in the comparison, so it fails.
I’m pretty new to scripting and I think what I’m getting wrong is the tokens and delimiters. Here’s the line from the registry when only a reg query is used:
Printer WPL-606 REG_SZ winspool,Ne07:
Can someone explain how I can go about getting this to pick out the correct part of the registry?
Querying the registry, and with the tokens/delims you are using, you are grabbing the entire line output. You need to set spaces as your delims and grab the first 2 tokens. You would want the following:
Or you can use
PRNMNGR. It’s a VBS script localized in .\windows\system32\prnmngr.vbs that helps you to manage printers (including listing them). So it would go like this:You can check out the command in CMD with
PRNMNGR /?