JSI Tip 10550. How can I display each computers connections to served printers in my domain?

Each computers connections to served printers is recorded in the registry at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Connections. Using REG.EXE, built into Windows XP, Windows Server 2003, and later operating systems, or installed from the Windows 2000 Support Tools, I have scripted PrinterConnections.bat to generate a CSV file that contains connections to served printers in your domain.

The syntax for using PrinterConnections.bat is:

PrinterConnections CSVFile

Where CSVFile is the file that will contain the CSV file that contains:

"ComputerName","Server","PrinterShare"

PrinterConnections.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: PrinterConnections CSVFile&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set csvfile=%1
if exist %csvfile% del /q %csvfile%
set dom=%USERDOMAIN%
set key=HKLM\SYSTEM\CurrentControlSet\Control\Print\Connections
set b1=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Connectionsfor /f "Tokens=1" %%c in ('net view /domain:%dom%^|Findstr /L /C:"\\"') do (
 call :quiet %%c>nul 2>&1
)
endlocal
goto :EOF
:quiet
set work=%1
set comp=%work:~2%
for /f "Tokens=2* Delims=," %%p in ('reg query %1\%key%^|find /i "%b1%"') do (
  @echo "%comp%","%%p","%%q">>%csvfile%
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish