Open-AudIT
https://www.open-audit.org/phpBB3/

Printers
https://www.open-audit.org/phpBB3/viewtopic.php?f=20&t=3877
Page 1 of 1

Author:  Mark [ Tue Nov 23, 2010 10:35 pm ]
Post subject:  Printers

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]

Author:  JayDee [ Wed Nov 24, 2010 1:39 am ]
Post subject:  Re: Printers

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]

Author:  Mark [ Wed Nov 24, 2010 7:10 am ]
Post subject:  Re: Printers

Thanks JayDee, much appreciated.

Author:  wnyhelpdesk [ Thu Nov 25, 2010 1:34 am ]
Post subject:  Re: Printers

==========================================
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]

Author:  Mark [ Thu Nov 25, 2010 6:53 am ]
Post subject:  Re: Printers

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 ?

Author:  wnyhelpdesk [ Thu Nov 25, 2010 7:14 am ]
Post subject:  Re: Printers

I am also pretty sure it's a per user setting.

Page 1 of 1 All times are UTC + 10 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/