Solved

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

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
Numerous times I have been asked this questions that what is it that makes my machine log on so slow, there have been cases where computers took 23 minute exactly after taking password and getting to the desktop. Interesting thing was the fact th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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