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
Solved

Script to check printer status

Posted on 2010-08-16
6
1,660 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

840 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