Page 1 of 1 1
Topic Options
#26624 - 2002-08-07 01:41 PM Printer Audit/List
ftaylor Offline
Fresh Scripter

Registered: 2002-08-06
Posts: 5
Loc: East Coast
Greetings all!

Just trying something simple(ish) for my first Kix outting and gotten quite a bit somewhat hacked together but here's what I want to do:

List to a file all printers installed on that machine for that user.

The file needs to be named after the username and computername. For example J500H53-JSMITH.txt - where J500H53 is the computer name and JSMITH the username.

The registry key under NT/2K/XP seems to be: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

Any ideas on this would be very much appreciated! Extracting the Registry info is fine, and also the username and computer name. Writing that all to a file is where I stumble.

Thanks for reading all!

Top
#26625 - 2002-08-07 02:04 PM Re: Printer Audit/List
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
I prefer to use WMI when auditing for Printers, Drives, Shares, etc as it seems to be a little more reliable - also there are less exceptions one may have to account for.

If you check out some of the threads on the board found by searching under "WMI" or "audit" or "inventory", you should find plenty of ideas to get you started.

This is an excerpt of my audit script, which writes info to an Access database. I've just printed here the bits that pull printer info from WMI.

code:
$WMI = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//@WKSTA"
$WMI_PRINTERS = "SELECT * FROM WIN32_PRINTER"
$Printers = GetObject($WMI).ExecQuery($WMI_PRINTERS)
For Each $Printer In $Printers
$PrinterID = $Printer.DeviceID
$DriverName = $Printer.DriverName
$PortName = $Printer.PortName
$Description = $Printer.Description
;Code to write the info for each printer should go here
Next

As far as writing to a file goes, its a fairly simple process, consisting of three steps. 1) Open the file. 2) Write whatever info you desire to the file. 3) Close the file again when done.

Something like this should give you an idea:

code:
$x = Open(1,"\\server\share\file.log",5)
$x = Writeline(1,"Data collected from " + @WKSTA + " - " + @USERID + " - " + @DATE + " " + @TIME + CHR(13) + CHR (10))
$x = Close(1)

See the Kix manual for more info on what the various parameters of this code actually do. One other option you may want to consider is using RedirectOutput() to write to a file - this command encapsulates the opening and closing in itself and may be better for writing a lot of info, rather than one line in a logfile. Depends on your needs and personal preference, I would say.

Hope this helps - oh, and welcome to the board!

-Breaker

[ 07. August 2002, 14:05: Message edited by: Breaker ]
_________________________
================================================
Breaker


Top
#26626 - 2002-08-07 09:55 PM Re: Printer Audit/List
ftaylor Offline
Fresh Scripter

Registered: 2002-08-06
Posts: 5
Loc: East Coast
Thank you kindly, worked on that today and it's up and looks good!

Again, thanks!

Top
#26627 - 2002-12-02 11:12 AM Re: Printer Audit/List
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

For people who can't use WMI see our script [b]printers.kix[/]b on our site.
Script creates dynamic lists.
greetings.

btw: symbol  - on our homepage has been linked to related http://kixtart.org topic.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


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

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.053 seconds in which 0.026 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