Solved

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

Posted on 2006-11-29
7
878 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
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Pber
Comment Utility
0
 

Author Comment

by:Richard_Wilson
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. Script just ran fine for me, including a couple of adjustments. Found this question via Google.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
Learn about cloud computing and its benefits for small business owners.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now