Registrations to Open-AudIT forums are now closed. To ask any new questions please visit Opmantek Community Questions.

Open-AudIT

What's on your network?
It is currently Thu Mar 28, 2024 11:33 pm

All times are UTC + 10 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Printers
PostPosted: Tue Nov 23, 2010 10:35 pm 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1964
Location: Brisbane, Australia
Could anyone run the code below (replace the computername in arrComputers) and post the output (please) ! I am away from work, so can't test this...

TIA.
Mark.



[code]On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
set objShell = CreateObject("WScript.Shell")

arrComputers = Array("COMPUTER_NAME_GOES_HERE")
on error resume next
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems

printer_ip_address = ""
printer_hostname = ""
printer_system_key = ""
printer_manufacturer = ""

if (InStr(objItem.PortName, "IP_") = 1) then
printer_ip_address = mid(objItem.PortName, 4)
Dim objExec
Set objExec = objShell.Exec( "nslookup " & printer_ip_address )
Dim objStream
k = ""
For Each objStream In Array( objExec.StdOut, objExec.StdErr )
Do Until objStream.AtEndOfStream
line = objStream.ReadLine()
if (InStr(line, "Name") = 1) then
i = split(line, ".")
k = mid(i(0), 6)
k = ltrim(k)
end if
Loop
Next
if (k <> "") then
printer_hostname = k
else
printer_hostname = printer_ip_address
end if
else
printer_ip_address = ""
end if


wscript.echo "<printer>"
wscript.echo " <printer_ip_address>" & printer_ip_address & "</printer_ip_address>"
wscript.echo " <printer_hostname>" & printer_hostname & "</printer_hostname>"

if (printer_ip_address > "") then
printer_system_key = printer_ip_address
else
printer_system_key = strComputer & "_" & replace(objItem.DeviceID, " ", "_")
end if

wscript.echo " <printer_system_key>" & printer_system_key & "</printer_system_key>"

wscript.echo " <printer_uuid>" & replace(objItem.DeviceID, " ", "_") & "</printer_uuid>"

WScript.Echo " <printer_description>" & objItem.Comment & "</printer_description>"

wscript.echo " <printer_icon>printer</printer_icon>"

printer_model = replace(objItem.DriverName, " PCL 5", "")
printer_model = replace(printer_model, " PCL 6", "")
printer_model = replace(printer_model, " PS", "")

wscript.echo " <printer_model>" & printer_model & "</printer_model>"


if (instr(printer_model, "HP ") = 1) then printer_manufacturer = "Hewlett Packard" end if
if (instr(printer_model, "Xerox") = 1) then printer_manufacturer = "Xerox" end if
if (instr(printer_model, "Lexmark") = 1) then printer_manufacturer = "Lexmark" end if
if (instr(printer_model, "Ricoh") = 1) then printer_manufacturer = "Ricoh" end if
if (instr(printer_model, "Toshiba") = 1) then printer_manufacturer = "Toshiba" end if
if (instr(printer_model, "Fiery") = 1) then printer_manufacturer = "Konica Minolta" end if
if (instr(printer_model, "Konica") = 1) then printer_manufacturer = "Konica Minolta" end if
if (instr(printer_model, "LAN-Fax") = 1) then printer_manufacturer = "Ricoh" end if
if (instr(printer_model, "Canon") = 1) then printer_manufacturer = "Canon" end if
if (instr(printer_model, "Color-MFPe") = 1) then printer_manufacturer = "Toshiba" end if
if (instr(printer_model, "FX Document") = 1) then printer_manufacturer = "Xerox" end if
if (instr(printer_model, "EasyCoder") = 1) then printer_manufacturer = "Intermec" end if
if (instr(printer_model, "Oce") = 1) then printer_manufacturer = "Oce" end if


wscript.echo " <printer_manufacturer>" & printer_manufacturer & "</printer_manufacturer>"
WScript.Echo " <printer_port_name>" & objItem.PortName & "<printer_port_name>"

WScript.Echo " <printer_shared>" & objItem.Shared & "</printer_shared>"
WScript.Echo " <printer_share_name>" & objItem.ShareName & "</printer_share_name>"
WScript.Echo " <printer_location>" & objItem.Location & "</printer_location>"
wscript.echo "</printer>"


'WScript.Echo "Caption: " & objItem.Caption
'WScript.Echo "DeviceID: " & objItem.DeviceID
'WScript.Echo "DriverName: " & objItem.DriverName
'WScript.Echo "Local: " & objItem.Local
'WScript.Echo "Name: " & objItem.Name
'WScript.Echo "Network: " & objItem.Network
'WScript.Echo "ServerName: " & objItem.ServerName
'WScript.Echo
'WScript.Echo
'WScript.Echo
'exit for
Next
Next[/code]

_________________
Support and Development hours available from [url=https://opmantek.com]Opmantek[/url].
Please consider a purchase to help make Open-AudIT better for everyone.


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Wed Nov 24, 2010 1:39 am 
Offline
Helper

Joined: Tue Jul 25, 2006 2:33 am
Posts: 83
Location: Hampshire, UK
Mark,
Hope this is what you need...

John
[code]C:\Documents and Settings\xxxx\Desktop>cscript ptest.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.


==========================================
Computer: LAPT-006
==========================================
<printer>
<printer_ip_address></printer_ip_address>
<printer_hostname></printer_hostname>
<printer_system_key>LAPT-006_Send_To_OneNote_2007</printer_system_key>
<printer_uuid>Send_To_OneNote_2007</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>Send To Microsoft OneNote Driver</printer_model>
<printer_manufacturer></printer_manufacturer>
<printer_port_name>Send To Microsoft OneNote Port:<printer_port_name>
<printer_shared>False</printer_shared>
<printer_share_name></printer_share_name>
<printer_location></printer_location>
</printer>
<printer>
<printer_ip_address></printer_ip_address>
<printer_hostname></printer_hostname>
<printer_system_key>LAPT-006_RealFA$T_PDF_Converter</printer_system_key>
<printer_uuid>RealFA$T_PDF_Converter</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>Amyuni Document Converter 2.10</printer_model>
<printer_manufacturer></printer_manufacturer>
<printer_port_name>LPT1:<printer_port_name>
<printer_shared>False</printer_shared>
<printer_share_name></printer_share_name>
<printer_location></printer_location>
</printer>
<printer>
<printer_ip_address></printer_ip_address>
<printer_hostname></printer_hostname>
<printer_system_key>LAPT-006_Microsoft_XPS_Document_Writer</printer_syste
m_key>
<printer_uuid>Microsoft_XPS_Document_Writer</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>Microsoft XPS Document Writer</printer_model>
<printer_manufacturer></printer_manufacturer>
<printer_port_name>XPSPort:<printer_port_name>
<printer_shared>False</printer_shared>
<printer_share_name></printer_share_name>
<printer_location></printer_location>
</printer>
<printer>
<printer_ip_address></printer_ip_address>
<printer_hostname></printer_hostname>
<printer_system_key>LAPT-006_hp_photosmart_7150_series</printer_system_ke
y>
<printer_uuid>hp_photosmart_7150_series</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>hp photosmart 7150 series</printer_model>
<printer_manufacturer></printer_manufacturer>
<printer_port_name>DOT4_001<printer_port_name>
<printer_shared>False</printer_shared>
<printer_share_name></printer_share_name>
<printer_location></printer_location>
</printer>
<printer>
<printer_ip_address>192.168.1.247</printer_ip_address>
<printer_hostname>192.168.1.247</printer_hostname>
<printer_system_key>192.168.1.247</printer_system_key>
<printer_uuid>HP_LaserJet_2100_Series_PS</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>HP LaserJet 2100 Series</printer_model>
<printer_manufacturer>Hewlett Packard</printer_manufacturer>
<printer_port_name>IP_192.168.1.247<printer_port_name>
<printer_shared>False</printer_shared>
<printer_share_name></printer_share_name>
<printer_location></printer_location>
</printer>
<printer>
<printer_ip_address></printer_ip_address>
<printer_hostname></printer_hostname>
<printer_system_key>LAPT-006_\\KSCSRV03\HP_CLJ_4700</printer_system_key>
<printer_uuid>\\KSCSRV03\HP_CLJ_4700</printer_uuid>
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>HP Color LaserJet 4700</printer_model>
<printer_manufacturer>Hewlett Packard</printer_manufacturer>
<printer_port_name>HPColorLaserJet4700_copy_1<printer_port_name>
<printer_shared>True</printer_shared>
<printer_share_name>HP CLJ 4700</printer_share_name>
<printer_location>Plotter Room</printer_location>
</printer>

C:\Documents and Settings\xxxx\Desktop>[/code]

_________________
OA environment:
OA Server: Ubuntu 10.04LTS
1 Windows 2008R2 Server
4 Windows 2003 Servers
20 Windows XP workstations
1 Windows 7 workstation
2 Ubuntu 11.10 servers
Misc other networked items


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Wed Nov 24, 2010 7:10 am 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1964
Location: Brisbane, Australia
Thanks JayDee, much appreciated.

_________________
Support and Development hours available from [url=https://opmantek.com]Opmantek[/url].
Please consider a purchase to help make Open-AudIT better for everyone.


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Thu Nov 25, 2010 1:34 am 
Offline
Newbie

Joined: Thu Feb 11, 2010 2:41 am
Posts: 19
==========================================
Computer: localhost
==========================================
<printer>
<printer_ip_address>10.16.120.65</printer_ip_address>
<printer_hostname>10.16.120.65</printer_hostname>
<printer_system_key>10.16.120.65</printer_system_key>
<printer_uuid>\\dcnj01\PRTNJ65</printer_uuid>
<printer_description>10.16.120.65</printer_description>
<printer_icon>printer</printer_icon>
<printer_model>HP LaserJet P4010_P4510 Series</printer_model>
<printer_manufacturer>Hewlett Packard</printer_manufacturer>
<printer_port_name>IP_10.16.120.65<printer_port_name>
<printer_shared>True</printer_shared>
<printer_share_name>PRTNJ65</printer_share_name>
<printer_location>5th Floor Printer</printer_location>
</printer>

How about finding out if it's the default printer?

[color=#FF4000]Output:[/color]
==========================================
Computer: localhost
==========================================
<printer>
<printer_ip_address>10.16.120.65</printer_ip_address>
<printer_hostname>10.16.120.65</printer_hostname>
<printer_system_key>10.16.120.65</printer_system_key>
<printer_uuid>\\dcnj01\PRTNJ65</printer_uuid>
[color=#808080]<printer_default> Yes </printer_default>[/color]
<printer_description>10.16.120.65</printer_description>
<printer_icon>printer</printer_icon>
<printer_model>HP LaserJet P4010_P4510 Series</printer_model>
<printer_manufacturer>Hewlett Packard</printer_manufacturer>
<printer_port_name>IP_10.16.120.65<printer_port_name>
<printer_shared>True</printer_shared>
<printer_share_name>PRTNJ65</printer_share_name>
<printer_location>5th Floor Printer</printer_location>
</printer>
<printer>
<printer_ip_address>10.16.120.57</printer_ip_address>
<printer_hostname>10.16.120.57</printer_hostname>
<printer_system_key>10.16.120.57</printer_system_key>
<printer_uuid>\\JMCKINNEY\HP_Color_LaserJet_4700_PCL_5c</printer_uuid>
[color=#BFBFBF]<printer_default> No </printer_default>[/color]
<printer_description></printer_description>
<printer_icon>printer</printer_icon>
<printer_model>HP Color LaserJet 4700c</printer_model>
<printer_manufacturer>Hewlett Packard</printer_manufacturer>
<printer_port_name>IP_10.16.120.57<printer_port_name>
<printer_shared>True</printer_shared>
<printer_share_name>HPColorL</printer_share_name>
<printer_location></printer_location>
</printer>

[code]
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
set objShell = CreateObject("WScript.Shell")

arrComputers = Array("localhost")
on error resume next
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems

printer_ip_address = ""
printer_hostname = ""
printer_system_key = ""
printer_manufacturer = ""

if (InStr(objItem.PortName, "IP_") = 1) then
printer_ip_address = mid(objItem.PortName, 4)
Dim objExec
Set objExec = objShell.Exec( "nslookup " & printer_ip_address )
Dim objStream
k = ""
For Each objStream In Array( objExec.StdOut, objExec.StdErr )
Do Until objStream.AtEndOfStream
line = objStream.ReadLine()
if (InStr(line, "Name") = 1) then
i = split(line, ".")
k = mid(i(0), 6)
k = ltrim(k)
end if
Loop
Next
if (k <> "") then
printer_hostname = k
else
printer_hostname = printer_ip_address
end if
else
printer_ip_address = ""
end if


wscript.echo "<printer>"
wscript.echo " <printer_ip_address>" & printer_ip_address & "</printer_ip_address>"
wscript.echo " <printer_hostname>" & printer_hostname & "</printer_hostname>"

if (printer_ip_address > "") then
printer_system_key = printer_ip_address
else
printer_system_key = strComputer & "_" & replace(objItem.DeviceID, " ", "_")
end if

wscript.echo " <printer_system_key>" & printer_system_key & "</printer_system_key>"

wscript.echo " <printer_uuid>" & replace(objItem.DeviceID, " ", "_") & "</printer_uuid>"
if (GetDefaultPrinter = replace(objItem.DeviceID, " ", "_")) then
Wscript.Echo " <printer_default> Yes </printer_default>"
else
Wscript.Echo " <printer_default> No </printer_default>"
end if
WScript.Echo " <printer_description>" & objItem.Comment & "</printer_description>"

wscript.echo " <printer_icon>printer</printer_icon>"

printer_model = replace(objItem.DriverName, " PCL 5", "")
printer_model = replace(printer_model, " PCL 6", "")
printer_model = replace(printer_model, " PS", "")

wscript.echo " <printer_model>" & printer_model & "</printer_model>"


if (instr(printer_model, "HP ") = 1) then printer_manufacturer = "Hewlett Packard" end if
if (instr(printer_model, "Xerox") = 1) then printer_manufacturer = "Xerox" end if
if (instr(printer_model, "Lexmark") = 1) then printer_manufacturer = "Lexmark" end if
if (instr(printer_model, "Ricoh") = 1) then printer_manufacturer = "Ricoh" end if
if (instr(printer_model, "Toshiba") = 1) then printer_manufacturer = "Toshiba" end if
if (instr(printer_model, "Fiery") = 1) then printer_manufacturer = "Konica Minolta" end if
if (instr(printer_model, "Konica") = 1) then printer_manufacturer = "Konica Minolta" end if
if (instr(printer_model, "LAN-Fax") = 1) then printer_manufacturer = "Ricoh" end if
if (instr(printer_model, "Canon") = 1) then printer_manufacturer = "Canon" end if
if (instr(printer_model, "Color-MFPe") = 1) then printer_manufacturer = "Toshiba" end if
if (instr(printer_model, "FX Document") = 1) then printer_manufacturer = "Xerox" end if
if (instr(printer_model, "EasyCoder") = 1) then printer_manufacturer = "Intermec" end if
if (instr(printer_model, "Oce") = 1) then printer_manufacturer = "Oce" end if


wscript.echo " <printer_manufacturer>" & printer_manufacturer & "</printer_manufacturer>"
WScript.Echo " <printer_port_name>" & objItem.PortName & "<printer_port_name>"

WScript.Echo " <printer_shared>" & objItem.Shared & "</printer_shared>"
WScript.Echo " <printer_share_name>" & objItem.ShareName & "</printer_share_name>"
WScript.Echo " <printer_location>" & objItem.Location & "</printer_location>"
wscript.echo "</printer>"


'WScript.Echo "Caption: " & objItem.Caption
'WScript.Echo "DeviceID: " & objItem.DeviceID
'WScript.Echo "DriverName: " & objItem.DriverName
'WScript.Echo "Local: " & objItem.Local
'WScript.Echo "Name: " & objItem.Name
'WScript.Echo "Network: " & objItem.Network
'WScript.Echo "ServerName: " & objItem.ServerName
'WScript.Echo
'WScript.Echo
'WScript.Echo
'exit for
Next
Next


Function GetDefaultPrinter
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each oItem in colItems
If (oItem.Attributes And 2^(3-1)) = 4 Then
sDefault = oItem.Name
Exit For
End If
Next
GetDefaultPrinter = sDefault
End Function
[/code]


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Thu Nov 25, 2010 6:53 am 
Offline
Site Admin
User avatar

Joined: Mon Jun 07, 2004 11:48 am
Posts: 1964
Location: Brisbane, Australia
Default printer would be a USER attribute, correct ?
I assume it is...
I have stayed completely away from USER attributes, so far in OAv2.
I think I'll have to put them in though (sooner or later).
If it's an actual system setting, then definitely can put it in.

So - is it a user or system attribute ?

_________________
Support and Development hours available from [url=https://opmantek.com]Opmantek[/url].
Please consider a purchase to help make Open-AudIT better for everyone.


Top
 Profile  
Reply with quote  
 Post subject: Re: Printers
PostPosted: Thu Nov 25, 2010 7:14 am 
Offline
Newbie

Joined: Thu Feb 11, 2010 2:41 am
Posts: 19
I am also pretty sure it's a per user setting.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group