ARTICLE

Interrogating your Printer Queries with WMI

Posted by John O Donnell Articles | Printing in VB.NET June 25, 2003
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.
Download Files:
 
Reader Level:

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

share this article :
post comment
 

How does it work with remote printers, and how does it work with specific printers?

Posted by Uwe Schoeler Feb 02, 2007

The article looked just what I need for my project but the .ZIP file contains code for an animation program .

The header is

'Pocket PC Animate

'Shows some very basic animation code on the Pocket PC platform

'Written 04/26/02 by John O'Donnell - csharpconsulting@hotmail.com

Posted by David Silkstone Jul 06, 2006
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor