Cancelling the current print job immediately...

A

Ajab Gajab

Hi All,
I am developing an application in VB.Net where I need to provide user with
cancelling or stopping the current print job. Like, if a user clicks on
"stop" button, then printer should print already processed contents of a
page. This can be easily achieved in VB.Net by using e.HasMorePages = False.
However, if a user clicks on "Cancel" button, the printer should terminate
the current job immedialtely without printing processed contents of a page.
So, the page will be blank at the end. Has anybody got an idea on how to
achieve this?
 
L

LOZANO-MORÁN, Gabriel

According to the MDSN documentation the Win32_Printer WMI class has a method
called CancelAllJobs. This means that the following code should work but
take a look at the requirements.

Requirements:
Client: Requires Windows XP.
Server: Requires Windows Server 2003.

I cannot test this since I am developing at a client on a Win2K machine but
try it out.

Solution 1:
using System;
using System.Management;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
WqlObjectQuery objectQuery = new WqlObjectQuery("select *
from Win32_Printer");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
foreach (ManagementObject printer searcher.Get())
{
if(printer["Name"] == "myprinter") // you can filter on
the printer here

Console.WriteLine(printer.InvokeMethod("CancelAllJobs", null));
}
Console.Read();
}
}
}

Solution 2:
using System;
using System.Management;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
WqlObjectQuery objectQuery = new WqlObjectQuery("select *
from Win32_PrintJob");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
foreach (ManagementObject printJob searcher.Get())
{
printJob.InvokeMethod("CancelAllJobs", null);
}
Console.Read();
}
}
}

Gabriel Lozano-Morán
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top