JSI Tip 10371. How can I enumerate the print queues on a local or remote computer?


Using only standard commands, I have scripted PrintQue.bat to enumerate the printer queues on a local or remote computer.

The syntax for using PrintQue.bat is:

For /f "Tokens=*" %%p in ('PrintQue ComputerName') do (
 if "%%p" NEQ "NONE" @echo %%p
)
Where ComputerName is the NetBIOS computer name.

PrintQue.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax PrintQue comp &goto :EOF
setlocal
set comp=%1
set comp=%comp:"=%
set comp=%comp:\=%
if exist "%TEMP%\PrintQue.vbs" goto doit
@echo Dim oArgs>"%TEMP%\PrintQue.vbs"
@echo Set WshShell = WScript.CreateObject("WScript.Shell")>>"%TEMP%\PrintQue.vbs"
@echo Set oArgs = WScript.Arguments>>"%TEMP%\PrintQue.vbs"
@echo comp = oArgs(0)>>"%TEMP%\PrintQue.vbs"
@echo Set objServer = GetObject("WinNT://" ^& comp)>>"%TEMP%\PrintQue.vbs"
@echo objServer.Filter = Array("printQueue")>>"%TEMP%\PrintQue.vbs"
@echo For Each objPrinter In objServer>>"%TEMP%\PrintQue.vbs"
@echo.    Wscript.Echo objPrinter.Name>>"%TEMP%\PrintQue.vbs"
@echo Next>>"%TEMP%\PrintQue.vbs"
:doit
set OK=N
for /f "Tokens=*" %%p in ('cscript //nologo "%TEMP%\PrintQue.vbs" %comp%') do (
 set OK=Y
 @echo %%p
)
if "%OK%" EQU "N" @echo NONE
endlocal



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