Solved

Script to check printer status

Posted on 2010-08-16
6
1,726 Views
Last Modified: 2012-05-10
I have a server that hosts all of the network printers. I want a script that displays the current status of each printer (online, offline, out of paper etc...) to assist the Service Desk in proactively diagnosing faults.

The script I have so far is printer.hta and is displayed below:

<SCRIPT LANGUAGE = "VBScript">
Sub window_onLoad
 GetInfo
 iTimerID = window.setInterval("GetInfo", 60000, "VBScript")
End Sub
Sub GetInfo
 For i = (objTable.Rows.Length - 1) to 0 Step -1
 myNewRow = Document.All.objTable.deleteRow(i)
 Next
 Set objRow = objTableBody.InsertRow()
 objRow.Style.fontWeight = "bold"
 Set objCell = objRow.InsertCell()
 objCell.InnerText = "Name"
 Set objCell = objRow.InsertCell()
 objCell.InnerText = "Location"
 Set objCell = objRow.InsertCell()
 objCell.InnerText = "Status"
 strComputer = "CMRIS"
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & _
 strComputer & "\root\cimv2")
 Set colPrinters = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Printer")
 For Each objPrinter in colPrinters
 Set objRow = objTableBody.InsertRow()
 Set objCell = objRow.InsertCell()
 objCell.InnerText = objPrinter.Name
 Set objCell = objRow.InsertCell()
 objCell.InnerText = objPrinter.Location
 Set objCell = objRow.InsertCell()
 Select Case objPrinter.PrinterStatus
 Case 1
 strPrinterStatus = "Other"
 Case 2
 strPrinterStatus = "Unknown"
 Case 3
 strPrinterStatus = "Idle"
 Case 4
 strPrinterStatus = "Printing"
 Case 5
 strPrinterStatus = "Warming up"
 End Select
 objCell.InnerText = strPrinterStatus
 Next
End Sub
</SCRIPT>
<TABLE ID = "objTable" border = "1" >
<TBODY ID = "objTableBody">
</TBODY>
</TABLE>

Open in new window


My problem is I can't seem to get it to display all the printer statuses. Every printer that is not online is showing up as Unknown or Other. I would like it to be a bit more detailed than this.

Also, is it possible to sort them based on the status rather than by printer name?

Thank you.
0
Comment
Question by:IM&T SRFT
[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
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
Sarika30 earned 500 total points
ID: 33444505
May Be after this select case, you should add one more select case:


For Each objPrinter in colPrinters
Select Case objItem.DetectedErrorState
Case 0 Status = "On line"
Case 1 Status = "Paused"
Case 2 Status = "Pending Deletion"
Case 3 Status = "Error"
Case 4 Status = "Paper Jam"
Case 5 Status = "Paper Out"
Case 6 Status = "Manual Feed"
Case 7 Status = "Paper Problem"
Case 8 Status = "Offline"
Case 256 Status = "IO Active"
Case 512 Status = "Busy"
Case 1024 Status = "Printing"
Case 2048 Status = "Output Bin Full"
Case 4096 Status = "Not Available"
Case 8192 Status = "Waiting"
Case 6384 Status = "Processing"
Case 32768 Status = "Initializing"
Case 65536 Status = "Warming Up"
Case 131072 Status = "Toner Low"
Case 262144 Status = "No Toner"
Case 524288 Status = "Page Punt"
Case 1048576 Status = "User Intervention"
Case 2097152 Status = "Out of Memory"
Case 4194304 Status = "Door Open"
Case 8388608 Status = "Server Unknown"
Case 16777216 Status = "Power Save"
Case Else Status = "UNKNOWN"
End Select
0
 

Author Comment

by:IM&T SRFT
ID: 33445372
Where did you get those status codes from?
0
 

Author Comment

by:IM&T SRFT
ID: 33445424
They seem to conflict with what's written here: http://msdn.microsoft.com/en-us/library/aa387974%28v=VS.85%29.aspx
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 4

Expert Comment

by:Sarika30
ID: 33451605
I got it from here:
http://myitforum.com/cs2/blogs/dhite/archive/2008/08/17/vbs-script-to-retrieve-the-current-status-of-a-specified-printer-share.aspx

But i can see with your link that these might be wrong. You can try with the values given at the Microsoft website and then check if the results are ok. There is one more link, but it is pretty much similar to the link given given by you above:

http://msdn.microsoft.com/en-us/library/aa394363%28VS.85%29.aspx
0
 

Author Comment

by:IM&T SRFT
ID: 33464824
Is there a way of sorting the list by Status rather than Printer name?
0
 
LVL 4

Expert Comment

by:Sarika30
ID: 33471874
I dont think there is a way to sort them using any query. You will have to use some sorting technique like quick sort or bubble sort etc.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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