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
- @CLS
- @ECHO OFF
- FOR /F "skip=1 tokens=*" %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers" ^| FIND "["') DO CALL :REGREAD "%%x" ENDLOCAL
- GOTO:EOF
- :REGREAD
- SET P=%1
- SET P=%P:[=%
- SET P=%P:]=%
- SET P=%P:"=%
- ECHO.
- FOR /F "tokens=2* delims= " %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\%P%\Name"') DO ECHO Name: %%y
- FOR /F "tokens=2* delims= " %%x IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\%P%\Port"') DO ECHO Port: %%y
How it Works
- Clears the screen - Totally unnecessary, but nice for manual debugging.
- Turns Echo Off only the results and not the commands are seen in the
output.
- Returns the name of each key under Printers to the %1 variable to the
REGREAD portion of batch file.
- Skips to the end of the file after all the sub keys have been processed.
- Marks the beginning of the REGREAD procedure.
- Sets the result of the REG QUERY command to the variable P for processing.
- Strips the [ sign from the result of the REG QUERY.
- Strips the ] sign from the result of the REG QUERY.
- Strips the " marks from the result of the REG QUERY.
- Adds a blank line between each printer
- Echoes the value of the "Name" key under the %P registry key.
- 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