Question of the Week - May 6, 2002

Q.  I will be retiring some old servers that used to host network printers.  All the printers are now being serviced by new print servers.  How can I be assured that nobody is still referencing the old print server before it is decommissioned.

A.  I have used batch files in the past for similar functions.  The first batch file below will extract a list of all printers and their ports on a particular workstation.  The results can then be ported to a file on a network drive.  Then search the network drive for result files containing the text of the ports that will be disabled when the old server is taken off-line.

GETPRNT.BAT

  1. @CLS
  2. @ECHO OFF
  3. FOR /F "skip=1 tokens=*" %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers" ^| FIND "["') DO CALL :REGREAD "%%x" ENDLOCAL
  4. GOTO:EOF
  5. :REGREAD
  6. SET P=%1
  7. SET P=%P:[=%
  8. SET P=%P:]=%
  9. SET P=%P:"=%
  10. ECHO.
  11. FOR /F "tokens=2* delims=     " %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\%P%\Name"') DO ECHO Name: %%y
  12. FOR /F "tokens=2* delims=     " %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\%P%\Port"') DO ECHO Port: %%y

How it Works

  1. Clears the screen - Totally unnecessary, but nice for manual debugging.
  2. Turns Echo Off only the results and not the commands are seen in the output.
  3. Returns the name of each key under Printers to the %1 variable to the REGREAD portion of batch file.
  4. Skips to the end of the file after all the sub keys have been processed.
  5. Marks the beginning of the REGREAD procedure.
  6. Sets the result of the REG QUERY command to the variable P for processing.
  7. Strips the [ sign from the result of the REG QUERY.
  8. Strips the ] sign from the result of the REG QUERY.
  9. Strips the " marks from the result of the REG QUERY.
  10. Adds a blank line between each printer
  11. Echoes the value of the "Name" key under the %P registry key.
  12. Echoes the value of the "Port" key under the %P registry key.

Execute the patch file so that all the results are stored in unique names on a network drive.

Example - Z:GETPRNT.BAT >Z:\PRINTERS\%USERNAME%COMPUTERNAME%

Get REG.EXE -> http://download.microsoft.com/download/winntsrv40/rktools/1.0/NT4/EN-US/sp4rk_i386.Exe

Get GETPRNT.BAT -> http://www.ithowto.com./ftp/getprnt.bat