SMHAMK1985
(Lurker)
2006-06-15 08:20 PM
Log Installed Printers

Hello Together,

I would like log with KIXTART installed local - and network printers.

Can someone help me?

THANKS


NTDOCAdministrator
(KiX Master)
2006-06-15 08:26 PM
Re: Log Installed Printers

Hello and Welcome to the board.

Please take the time to read some of the FAQs and look in the UDF forum for code to do as you ask.

I will move this post to the STARTERS forum as the SCRIPTS forum is for discussion of code.


Mart
(KiX Supporter)
2006-06-15 09:22 PM
Re: Log Installed Printers

Have a look at PrinterList() - Creates an Array/List of Printers

Mart
(KiX Supporter)
2006-06-15 10:14 PM
Re: Log Installed Printers

As an answer to your question here two examples. The first writes to the screen the second writes to a file on c:\

Code:

Break on
$RC=SetOption("WrapAtEOL","on")

;shows the printers on your screen.
$array=printerlist()
For Each $printer in $array
? $printer
Next

;Writes all printer to a file.
$array=printerlist()
$rc = Open (1, "c:\installedprinters.txt", 5)
For Each $printer in $array
$rc = WriteLine (1, $printer + " is installed on: " + @WKSTA + @CRLF)
Next
$rc = Close(1)

;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:
;
;break on
;$RC=Setoption("WrapAtEOL","on")
;
;$array=printerlist()
;for each $printer in $array
; ? $printer
;next
;
;Source:
;
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



SMHAMK1985
(Lurker)
2006-06-15 10:55 PM
Re: Log Installed Printers

Wow, Thanks for your help. I test this Script exactly.



pvanwelt
(Fresh Scripter)
2007-04-16 04:58 PM
Re: Log Installed Printers

I'm getting this error when trying the script ... (kix 4.53)
I'm using windows XP and haven't installed anything of WMI, but isn't that included in windows XP ?


ERROR : Error in expression: this type of array not supported in expressions.!
Script: C:\kix\test.kix
Line : 39


Line 39 includes : $PrinterList=$printerdesc


Witto
(MM club member)
2007-04-16 07:05 PM
Re: Log Installed Printers

Dear pvanwelt
Could you start your own thread to ask a new question?
I think you do not equal the PrinterList() UDF to something
 Code:
Break On
Dim $arrPrinterList, $strPrinter
$arrPrinterList = PrinterList()
For Each $strPrinter in $arrPrinterList
	? $strPrinter
Next
; Do not forget to include the PrinterList() UDF


Dynamite Dan
(Fresh Scripter)
2008-04-29 04:33 PM
Re: Log Installed Printers

Could it be that the PrinterList() UDF only returns system printers installed or does it depends on the user performing the WMI query?

I tried to get a list of installed printers for the current users logged on the the pc's, however i get the feeling that i get a list of printers for my useraccount on the pc's.

PrinterList with option 0 to 3 gives me a list with results on the remote pc's, option 4 & 5 has no results.
The same query on the pc's i use (logged on or not) give good results with option 0,1,4 and 5. Options 2 & 3 resturn only local system printers.

how is it possible to retrieve the list of printer(s) of the current user logged on?


AllenAdministrator
(KiX Supporter)
2008-04-29 05:19 PM
Re: Log Installed Printers

You must have the proper permissions to get the list on the remote computer, as this UDF does rely on WMI.