Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-29
7
Medium Priority
?
891 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
5 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

879 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