This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
110} Can I use a script to determine if a specific printer exists?
Let's start with displaying the default printer
@echo off & setlocal enableextensions
cscript C:\WINDOWS\system32\prnmngr.vbs -g
endlocal & goto :EOF
The output could be e.g.
C:\_D\TEST>cmdfaq
The default printer is HP home DeskJet 500
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g
To list all of the printers for a computer
@echo off & setlocal enableextensions
cscript C:\WINDOWS\system32\prnmngr.vbs -l
endlocal & goto :EOF
If
the computer is on a network, for a specific printer one could try for
example
@echo off & setlocal enableextensions
set find_=HP DeskJet 895Cxi
net view \\%COMPUTERNAME%^
|findstr /c:"Print "^
|findstr /c:" %find_% ">nul
if %errorlevel% EQU 0 (
echo Found %find_%
) else (
echo Did not find %find_%)
endlocal & goto :EOF
The output would be e.g.
C:\_D\TEST>cmdfaq
Found HP DeskJet 895Cxi
The carets (^) in the code are used to divide a long command on
multiple lines.