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