JSI Tip 9734. How can a script return the local, remote, or all printer names available on my computer?


I have scripted LorRPrt.bat to return the local, remote, or all printer names available on your computer? The syntax for using LorRPrt.bat is:

LorRPrt \[B|L|R\]

If you run LorRPrt without any parameters, or with the B parameter, all available printers are returned. If you use the L parameter, only local printers are returned. If you use the R parameter, only remote printers are returned.

LorRPrt.bat contains:

@echo off
setlocal
set fnd=findstr /i /l "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 0"
if \{%1\}

\{\} goto Both if /i \{%1\}

\{B\} goto Both if /i \{%1\}

\{R\} set fnd=find "\\" if /i \{%1\}

\{L\} set fnd=find /V "\\" :Both set vb="%TEMP%\LorRPrt.vbs" if exist %vb% goto LorR @echo Dim oNet, oPrt, n>"%TEMP%\LorRPrt.vbs" @echo Set oNet = CreateObject("WScript.Network")>>"%TEMP%\LorRPrt.vbs" @echo Set oPrt = oNet.EnumPrinterConnections>>"%TEMP%\LorRPrt.vbs" @echo For n = 1 To oPrt.Count - 1 Step ^2>>"%TEMP%\LorRPrt.vbs" @echo. WScript.Echo oPrt.Item(n)>>"%TEMP%\LorRPrt.vbs" @echo Next>>"%TEMP%\LorRPrt.vbs" :LorR for /f "Tokens=*" %%a in ('cscript //nologo %vb%^|%fnd%') do ( @echo %%a ) endlocal
NOTE: See How do I retrieve the list of printers available on a print server, using a command?

NOTE: See What is the current user's default printer?

NOTE: See How do I print to a user's default printer in a CMD script?

NOTE: See How can I add a network printer remotely, so that it is available to all users?

NOTE: See How can I return the shortServerName, printShareName, printerName, location, portName, serverName, driverName, and distinguishedName of the Active Directory published printers?

NOTE: See How can I retrieve printer capability information from Active Directory?



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