;Function:
; PrinterList()
;
;Author:
; Allen Powell (Al_Po)
;
;Version:
; 1.3.1 (2006/05/10 fixed error detecting Print Servers sharing IP Printers)
;
;Revisions
; 1.3.0 (2005/10/21 added options to distinguish local or remote printers)
; 1.2.0 (2005/07/19 optimized code)
; 1.1.0 (2004/08/09 undimmed variable fix)
; 1.0.0 (2003/06/26 Original)
;
;Action:
; Creates an array/list of Printers, and optionally their ports installed, on a local or remote computer.&n bsp;
;
;Syntax:
; Printerlist(optional $remotepc,optional $displaymode)
;
;Parameters:
; $RemotePC: (Optional)
; Remote Computer. If omitted defaults to localpc.
; $DisplayMode (Optional)
; 0 - show all printers, don't display port info (Default)
; 1 - show all printers, display port info
; 2 - show local printers, don't display port info
; 3 - show local printers, display port info
; 4 - show remote printers, don't display port info
; 5 - show remote printers, display port info
;Returns:
; Array of Printers
;
;Dependencies:
; WMI
;
;Example:
;
COLOR g+/n
break on
$RC=Setoption("WrapAtEOL","on")
$array=printerlist()
for each $printer in $array
? $printer
next
Function PrinterList(optional $remotepc, optional $displaymode)
dim $service,$printer,$printers,$printerdesc[0],$counter,$portname,$printername
if $remotepc=""
$remotepc="."
endif
$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$Printers=$service.execquery ('select * from Win32_Printer')
for each $printer in $printers
redim preserve $printerdesc[$counter]
if $displaymode & 1
$portname = "," + $printer.portname
endif
select
case $displaymode & 4 ;remote printers
if left($printer.portname,2)="\\" or left($printer.name,2)=="\\"
$printername=$printer.name
endif
case $displaymode & 2 ;local printers
if left($printer.portname,2)<>"\\" and left($printer.name,2)<>"\\"
$printername=$printer.name
endif
case 1 ; all printers
$printername=$printer.name
endselect
if $printername<>""
$printerdesc[$counter]=$printername + $portname
$counter=$counter + 1
$printername=""
endif
next
$PrinterList=$printerdesc
endfunction
at (8,20) get $x