Page 1 of 1 1
Topic Options
#163311 - 2006-06-15 08:20 PM Log Installed Printers
SMHAMK1985 Offline
Lurker

Registered: 2006-06-15
Posts: 4
Hello Together,

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

Can someone help me?

THANKS

Top
#163312 - 2006-06-15 08:26 PM Re: Log Installed Printers
NTDOC Administrator Offline
Administrator
*****

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

Top
#163313 - 2006-06-15 09:22 PM Re: Log Installed Printers
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
Have a look at PrinterList() - Creates an Array/List of Printers
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#163314 - 2006-06-15 10:14 PM Re: Log Installed Printers
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
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



Edited by Mart (2006-06-15 10:18 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#163315 - 2006-06-15 10:55 PM Re: Log Installed Printers
SMHAMK1985 Offline
Lurker

Registered: 2006-06-15
Posts: 4
Wow, Thanks for your help. I test this Script exactly.


Top
#175417 - 2007-04-16 04:58 PM Re: Log Installed Printers [Re: SMHAMK1985]
pvanwelt Offline
Fresh Scripter

Registered: 2006-10-11
Posts: 17
Loc: Zierikzee, the Netherlands
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

Top
#175423 - 2007-04-16 07:05 PM Re: Log Installed Printers [Re: pvanwelt]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
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

Top
#187380 - 2008-04-29 04:33 PM Re: Log Installed Printers [Re: Witto]
Dynamite Dan Offline
Fresh Scripter

Registered: 2003-04-29
Posts: 20
Loc: BelgiŽ
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?

Top
#187382 - 2008-04-29 05:19 PM Re: Log Installed Printers [Re: Dynamite Dan]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4378
Loc: USA
You must have the proper permissions to get the list on the remote computer, as this UDF does rely on WMI.
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 172 anonymous users online.
Newest Members
FlyHorton, mschwj, Barchester, Evgeniy, kvanacker
17498 Registered Users

Generated in 0.033 seconds in which 0.01 seconds were spent on a total of 13 queries. Zlib compression enabled.

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