Solved

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

Posted on 2006-11-29
7
887 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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