Solved

Script to check printer status

Posted on 2010-08-16
6
1,571 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to share an MFP laser printer? 5 59
DHCP server 6 48
Looking for good easy switch for lab at home. 13 83
Excel copy picture into Outlook email 7 44
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

20 Experts available now in Live!

Get 1:1 Help Now