Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am writing a vb.net windows application to send pdf files to printer, one at time, after file is printed I want to get the status from printer as "Printed".

So far I have the code (working) which can send the selected pdf to printer.
Now I am trying to use this following code to get the status of printer, after the file is printed. but, not working.

The objCollection value is being set to "printer property evaluation failed".

Please help me if anyone knows how to do it.

VB.NET
Imports System.Management 'used namespace

Private objOS As ManagementObjectSearcher
Private objCollection As ManagementObjectCollection
Private objMgmt As ManagementObject

Dim jobName As String
Dim documentName As String
Dim PrinterStatus As String
Dim PrinterStatus1 As String


Dim searchQuery As String
Dim objMgmt As ManagementObject
searchQuery = "SELECT * FROM Win32_PrintJob"
objOS = New ManagementObjectSearcher(searchQuery)
objCollection = objOS.Get()

Try
For Each objMgmt In objCollection
jobName = objMgmt.Properties("Name").Value.ToString()
documentName = objMgmt.Properties("Document").Value.ToString()
PrinterStatus = objMgmt.Properties("Status").Value.ToString()
PrinterStatus1 = objMgmt.Properties("StatusMask").Value.ToString()
If PrinterStatus1 = "128" Then '128 means Printed
Change_Status()'write the status to database as printed
Else
MsgBox("objMgmt: " + documentName + "Status: " + PrinterStatus1, vbExclamation)
End If
Next

Catch ex As Exception
End Try


Thanks in advance!
Anita.
Posted
Updated 16-Mar-10 1:57am
v4

You need to specify Printer Name along with the server name..

I tried using following code and it's working fine..
VB
Dim printerNAme As String = "\\jayant\\MicrosftXpsPrinter" '\\Server\\PrinterName

other code will be as it is..
VB
Dim printerNAme As String = "\\jayant\\MicrosftXpsPrinter"
searchQuery = "SELECT * FROM Win32_Printer WHERE Name LIKE '" & printerNAme & "'"
objOS = New ManagementObjectSearcher(searchQuery)
objCollection = objOS.Get()


Go through this link, it covers all printing related forums
Get Printer Status[]


Hope it helps
 
Share this answer
 
v2
Hi,
Thank you for your reply.

I tried both of the following, but doesn't work.

searchQuery = "SELECT * FROM Win32_PrintJob WHERE Name LIKE '" & strPinter & "'"

searchQuery = "SELECT * FROM Win32_Printer WHERE Name = '\\LM103\\HPLaserjet4200tn-Claims'"

The following query
searchQuery = "SELECT * FROM Win32_PrintJob"

works on windows7 operating system which I am working on.
When I deploy the program to XP operating system, doesn't work.

It sends PDF to printer but doesn't get the status.

Please write if anyone has ideas.

Thank you,
Anita.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900