Solved

Script to check printer status

Posted on 2010-08-16
6
1,515 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Printers have changed substantially in the last 30 or so years, not just in technical capabilities but in cost and usage as well.  Printers were originally used for interfacing with the operator, not necessarily for printing copy or pictures. In …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

12 Experts available now in Live!

Get 1:1 Help Now