Page 1 of 1 1
Topic Options
#160400 - 2006-04-05 11:27 PM List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
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

Top
#160401 - 2006-04-06 12:20 AM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Did you try reading the liner notes?
;Syntax:
; Printerlist(optional $remotepc,optional $displaymode)
;
;Parameters:
; $RemotePC: (Optional)
; Remote Computer. If omitted defaults to localpc.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160402 - 2006-04-06 12:25 AM Re: List all Printers Installed on a Remote Print Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
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


Top
#160403 - 2006-04-06 12:35 AM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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


Edited by Les (2006-04-06 12:40 AM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160404 - 2006-04-06 02:21 AM Re: List all Printers Installed on a Remote Print Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
details, details

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

Top
#160405 - 2006-04-06 02:37 AM Re: List all Printers Installed on a Remote Print Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
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

 

Top
#160406 - 2006-04-06 05:08 PM Re: List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
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?

Top
#160407 - 2006-04-06 05:20 PM Re: List all Printers Installed on a Remote Print Server
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Just code like NTDOC supplied and change
Code:

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


to
Code:

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


Works for me

Top
#160408 - 2006-04-06 05:36 PM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160409 - 2006-04-06 05:38 PM Re: List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
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


Top
#160410 - 2006-04-06 05:47 PM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Did you trry my code? Did you security harden the server? Can you WMI browse from the PC running the script?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160411 - 2006-04-06 05:56 PM Re: List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
I tried your code and the server isn't security hardened, but how can wmi browse from the PC?
Top
#160412 - 2006-04-06 06:20 PM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160413 - 2006-04-07 07:31 PM Re: List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
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

Top
#160414 - 2006-04-07 07:40 PM Re: List all Printers Installed on a Remote Print Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
You can try replacing the @ERROR code with something like this to see what the error is.

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

Top
#160415 - 2006-04-07 07:48 PM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160416 - 2006-04-07 08:05 PM Re: List all Printers Installed on a Remote Print Server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160417 - 2006-04-07 08:33 PM Re: List all Printers Installed on a Remote Print Server
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
Error code 5 access denied. What possible factors would cause it from being denied? addprinterconnection works fine.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 176 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.061 seconds in which 0.019 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org