Solved

vb script to capture printer status  and write results to text file 2000 server

Posted on 2006-11-29
7
884 Views
Last Modified: 2012-08-13
actually for 2000 server but not it was not one of the categories

I need a vb script to capture network printer status (offline/out of paper/etc)
0
Comment
Question by:Richard_Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Pber
ID: 18039940
0
 

Author Comment

by:Richard_Wilson
ID: 18040135
results dont change regardless of out of paper etc.
testing with xp-pro and hp laserjet 5

in production this will be querying networked printers and routing new print jobs to different printers depending on the backlogs
0
 
LVL 26

Accepted Solution

by:
Pber earned 125 total points
ID: 18040529
It's only as good as the driver.  If the Print queue doesn't report properly, neither with WMI.  Thus if you see the status on your desktop printer object that you are out of paper, it should work with the script.

See this link regarding the objects:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp

strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:" & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters

    If objPrinter.Default = "True" Then
      Wscript.Echo "Name: " & objPrinter.Name
      Wscript.Echo "Status: " & GetStatus(objPrinter.PrinterStatus)
      Wscript.Echo "State: " & GetState(objPrinter.PrinterState)
      Wscript.Echo "ExtendedDetectedErrorState: " & objPrinter.ExtendedDetectedErrorState
      Wscript.Echo "ExtendedPrinterStatus: " & objPrinter.ExtendedPrinterStatus
    End If
Next

Function GetStatus(iCode)
      Select Case iCode
            Case 1 GetStatus = "Other"
            Case 2 GetStatus = "Unknown"
            Case 3 GetStatus = "Idle"
            Case 4 GetStatus = "Printing"
            Case 5 GetStatus = "Warmup"
            Case 6 GetStatus = "Stopped Printing"
            Case 7 GetStatus = "Offline"
            Case Else GetStatus = iCode
      End select
End Function

Function GetState(iCode)
      Select Case iCode
            Case 1 GetState = "Paused"
            Case 2 GetState = "Error"
            Case 3 GetState = "Pending Deletion"
            Case 4 GetState = "Paper Jam"
            Case 5 GetState = "Paper Out"
            Case 6 GetState = "Manual Feed"
            Case 7 GetState = "Paper Problem"
            Case 8 GetState = "Offline"
            Case 9 GetState = "IO Active"
            Case 10 GetState = "Busy"
            Case 11 GetState = "Printing"
            Case 12 GetState = "Output Bin Full"
            Case 13 GetState = "Not Available"
            Case 14 GetState = "Waiting"
            Case 15 GetState = "Processing"
            Case 16 GetState = "Initialization"
            Case 17 GetState = "Warming Up"
            Case 18 GetState = "Toner Low"
            Case 19 GetState = "No Toner"
            Case 20 GetState = "Page Punt"
            Case 21 GetState = "User Intervention Required"
            Case 22 GetState = "Out of Memory"
            Case 23 GetState = "Door Open"
            Case 24 GetState = "Server_Unknown"
            Case 25 GetState = "Power Save"
            Case Else GetState = iCode            
      End select
End Function
0
 
LVL 26

Expert Comment

by:Pber
ID: 18040638
Anyhow that script should work.

you should be able to trim what output you want by editing the Wscript.echo lines.
To output to a text file just do a:

cscript //nologo printer.vbs>ptrstatus.txt

this assumes you created the above script and saved it as printer.vbs
0
 
LVL 24

Expert Comment

by:SunBow
ID: 21797051
Thanks. Script just ran fine for me, including a couple of adjustments. Found this question via Google.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question