Reader Level:
ARTICLE

Interrogating your Printer Queries with WMI

Posted by John O Donnell Articles | Visual Basic .NET November 08, 2012
In response to a newsgroup query here is the code needed to view the printer queues on your system. Once again this is achieved using Windows Management Instrumentation or WMI. Note this code will display all printer queues if there are documents waiting to be printed. To test this open up a printer queue and pause the printer then use notepad or word etc and print to the paused printer.
  • 0
  • 0
  • 5323
Download Files:
 

In response to a newsgroup query here is the code needed to view the printer queues on your system. Once again this is achieved using Windows Management Instrumentation or WMI. Note this code will display all printer queues if there are documents waiting to be printed. To test this open up a printer queue and pause the printer then use notepad or word etc and print to the paused printer.

This code has been written on the release version of .NET.

'WMI4.vb
'Demonstrates how to view printjobs for any given printer
Imports System
Imports System.Management
Namespace WMI4
Class Class1
'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads
Shared Sub Main(args() As String)
Console.WriteLine("Retrieving printer queue information using WMI")
Console.WriteLine("===================================")
'Query printer queue
Dim oq As New System.Management.ObjectQuery("SELECT * FROM Win32_PrintJob") '
Dim query1 As New ManagementObjectSearcher(oq)
Dim queryCollection1 As ManagementObjectCollection = query1.Get()
Dim mo As ManagementObject
For Each mo In queryCollection1
Console.WriteLine(("Printer Driver : " + mo("DriverName").ToString()))
Console.WriteLine(("Document Name : " + mo("Document").ToString()))Console.WriteLine(("Document Owner : " + mo("Owner").ToString()))

Console.WriteLine("===========================")
Next mo
End Sub 'Main
End Class 'Class1
End Namespace 'WMI4

COMMENT USING

Trending up