Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sat 15-May-2010 17:27:04

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

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.
  The default printer is HP home DeskJet 500

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.
  Found HP DeskJet 895Cxi

The carets (^) in the code are used to divide a long command on multiple lines.

  hh ntcmds.chm::/net_view.htm
  hh ntcmds.chm::/findstr.htm
  prnmngr.vbs 2