AdamBarnett
MIS
I have a working vbscript that currently exports printer information to a text file as shown below. I need to be able to view the printer port's IP address into this script. Since this falls under the class w32.tcpipprinterport and not under w32.printer which my script is utilizing...i need help in "combining" the two classes. My working script is below:
Option Explicit
On Error Resume Next
Dim fso, src, dest, ts, output, temp, groups, user,WshShell,objWMIService,colInstalledPrinters,objPrinter,strPrinterStatus
Set fso = CreateObject("Scripting.FileSystemObject")
src = "computers.txt"
dest = "printers.csv"
If Not fso.FileExists(src) Then
WScript.Echo "File: """& src & " cannot be found."
Else
Set ts = fspenTextFile(src,1)
Set output = fso.CreateTextFile(dest,True)
Do Until ts.AtEndOfStream
temp = ts.ReadLine
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & temp & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
output.WriteLine string(0,vbtab) & objPrinter.ServerName
output.WriteLine ("STATUS") & vbTab & vbTab & ("PRINTER NAME") & vbTab & vbTab & ("CURRENT ACTIVE PORT")
output.writeline
For Each objPrinter in colInstalledPrinters
Select Case objPrinter.PrinterState
Case "0"
strPrinterStatus = "Ready"
Case "131072"
strPrinterStatus = "Toner Low"
Case "1024"
strPrinterStatus = "Printing"
Case "2"
strPrinterStatus = "Error"
Case "128"
strPrinterStatus = "Offline"
End Select
output.WriteLine string(0,vbTab) & strPrinterStatus & string(2,vbTab) & objPrinter.name & string(2,vbtab) & objPrinter.PortName
Next
Loop
End If
------------------------------------------
Thanks to anyone that can provide me a solution.
Ada
Option Explicit
On Error Resume Next
Dim fso, src, dest, ts, output, temp, groups, user,WshShell,objWMIService,colInstalledPrinters,objPrinter,strPrinterStatus
Set fso = CreateObject("Scripting.FileSystemObject")
src = "computers.txt"
dest = "printers.csv"
If Not fso.FileExists(src) Then
WScript.Echo "File: """& src & " cannot be found."
Else
Set ts = fspenTextFile(src,1)
Set output = fso.CreateTextFile(dest,True)
Do Until ts.AtEndOfStream
temp = ts.ReadLine
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & temp & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
output.WriteLine string(0,vbtab) & objPrinter.ServerName
output.WriteLine ("STATUS") & vbTab & vbTab & ("PRINTER NAME") & vbTab & vbTab & ("CURRENT ACTIVE PORT")
output.writeline
For Each objPrinter in colInstalledPrinters
Select Case objPrinter.PrinterState
Case "0"
strPrinterStatus = "Ready"
Case "131072"
strPrinterStatus = "Toner Low"
Case "1024"
strPrinterStatus = "Printing"
Case "2"
strPrinterStatus = "Error"
Case "128"
strPrinterStatus = "Offline"
End Select
output.WriteLine string(0,vbTab) & strPrinterStatus & string(2,vbTab) & objPrinter.name & string(2,vbtab) & objPrinter.PortName
Next
Loop
End If
------------------------------------------
Thanks to anyone that can provide me a solution.
Ada