hoopes
(Fresh Scripter)
2006-04-05 11:27 PM
List all Printers Installed on a Remote Print Server

Hi, how would I list ALL installed printers on a remote print server? I've tried the PrinterList() UDF but it will only display locally installed printers. This is what I've tried:

Code:

$array=printerlist()
for each $printer in $array
? $printer
next



Thanks for any suggestions!

Hoopes


Les
(KiX Master)
2006-04-06 12:20 AM
Re: List all Printers Installed on a Remote Print Server

Did you try reading the liner notes?
;Syntax:
; Printerlist(optional $remotepc,optional $displaymode)
;
;Parameters:
; $RemotePC: (Optional)
; Remote Computer. If omitted defaults to localpc.


NTDOCAdministrator
(KiX Master)
2006-04-06 12:25 AM
Re: List all Printers Installed on a Remote Print Server

Quote:

Hi, how would I list ALL installed printers on a remote print server? I've tried the PrinterList() UDF but it will only display locally installed printers. This is what I've tried:

Thanks for any suggestions!

Hoopes





Well because you're not using it correctly.


Code:

$array='system1,system2,system3'
for each $printer in $array
printerlist($printer)
next



Les
(KiX Master)
2006-04-06 12:35 AM
Re: List all Printers Installed on a Remote Print Server

DOC,
You too, need to learn to read.
;Action:
; Creates an array/list of Printers, and optionally their ports installed, on a local or remote computer.

;Returns:
; Array of Printers


NTDOCAdministrator
(KiX Master)
2006-04-06 02:21 AM
Re: List all Printers Installed on a Remote Print Server

details, details

well that's the general idea, just need to code a little different for the array that's returned is all.


NTDOCAdministrator
(KiX Master)
2006-04-06 02:37 AM
Re: List all Printers Installed on a Remote Print Server

Okay, then this should work just fine.


Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $ComputerList, $PrinterArray, $Comp, $Printer
$ComputerList = Split('system1,system2,system3,system4,system5',',')
For Each $Comp In $ComputerList
If $Comp
$PrinterArray=PrinterList($Comp)
For Each $Printer In $PrinterArray
'Computer: ' + $Comp + ' ' + $Printer ?
Next
EndIf
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)="\\"
$printername=$printer.name
EndIf
Case $displaymode & 2 ;local printers
If Left($printer.portname,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

 


hoopes
(Fresh Scripter)
2006-04-06 05:08 PM
Re: List all Printers Installed on a Remote Print Server

I only have one print server so I'm assuming this is the way it's supposed to look:

Code:

Dim $PrinterArray, $Printer
$PrinterArray=PrinterList('printserver') ; is it supposed to be \\printsever or printserver? I've tried both and neither work.
For Each $Printer In $PrinterArray
'Computer: ' + $Printer ?
Next



The problem is that it still isn't displaying any printers. Any ideas?


Witto
(MM club member)
2006-04-06 05:20 PM
Re: List all Printers Installed on a Remote Print Server

Just code like NTDOC supplied and change
Code:

$ComputerList = Split('system1,system2,system3,system4,system5',',')


to
Code:

$ComputerList = Split('printserver',',')


Works for me


Les
(KiX Master)
2006-04-06 05:36 PM
Re: List all Printers Installed on a Remote Print Server

This works for me.
Code:
Break On
For Each $Printer in Printerlist('FFPrint')
$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)="\\"
$printername=$printer.name
endif
case $displaymode & 2 ;local printers
if left($printer.portname,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




hoopes
(Fresh Scripter)
2006-04-06 05:38 PM
Re: List all Printers Installed on a Remote Print Server

Still a no go. Does it have something to do with W2K3?

Code:

break on
dim $SO
$SO=setoption('explicit','on')
$SO=setoption('novarsinstrings','on')
$SO=setoption('nomacrosinstrings','on')

dim $COMPUTERlIST, $PRINTERARRAY, $COMP, $PRINTER
$COMPUTERLIST = split('forest',',')
for each $COMP in $COMPUTERLIST
if $COMP
$PRINTERARRAY=printerlist($COMP)
for each $PRINTER in $PRINTERARRAY
'Computer: ' + $COMP + ' ' + $PRINTER ?
next
endIf
next



Les
(KiX Master)
2006-04-06 05:47 PM
Re: List all Printers Installed on a Remote Print Server

Did you trry my code? Did you security harden the server? Can you WMI browse from the PC running the script?

hoopes
(Fresh Scripter)
2006-04-06 05:56 PM
Re: List all Printers Installed on a Remote Print Server

I tried your code and the server isn't security hardened, but how can wmi browse from the PC?

Les
(KiX Master)
2006-04-06 06:20 PM
Re: List all Printers Installed on a Remote Print Server

There are commercial WMI browsers and free ones too. THere are also lots of WMI UDFs that you can use to query with and even the some KiXomatic stuff.

hoopes
(Fresh Scripter)
2006-04-07 07:31 PM
Re: List all Printers Installed on a Remote Print Server

The command:

Code:

wmic.exe printerconfig get caption /format:table | qgrep.exe -v Caption



Lists all of my printers but I can only run wmic.exe as administrator.

One thing that I did notice is that it is exiting in the IF statement in the PrinterList() function:

Code:


$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
If @error
? "Errors dicovered. " + @ERROR
Exit @error
EndIf



It's returning error code: -2147024891


NTDOCAdministrator
(KiX Master)
2006-04-07 07:40 PM
Re: List all Printers Installed on a Remote Print Server

You can try replacing the @ERROR code with something like this to see what the error is.

Exit Val('&' + Right(DecToHex(@ERROR), 4))


Les
(KiX Master)
2006-04-07 07:48 PM
Re: List all Printers Installed on a Remote Print Server

Are you running the KiX code as administrator?
What is the purpose of doing this? I hope you don't plan to enum the printers in a regular logon script.


Les
(KiX Master)
2006-04-07 08:05 PM
Re: List all Printers Installed on a Remote Print Server

If this is an admin script used to build an INI file for the users to draw from, you could also use remote registry reads from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares. You would still need to separate the file shares from the printer shares but that would be simple enough.

hoopes
(Fresh Scripter)
2006-04-07 08:33 PM
Re: List all Printers Installed on a Remote Print Server

Error code 5 access denied. What possible factors would cause it from being denied? addprinterconnection works fine.