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

Jerold Schulman

September 12, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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 offsetlocalset 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 Bothif /i {%1}
{B} goto Bothif /i {%1}
{R} set fnd=find "\"if /i {%1}
{L} set fnd=find /V "\":Bothset 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":LorRfor /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?



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like