473,513 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancelling the current print job immediately...

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?

--
..Net Developer
Nov 21 '05 #1
1 3370
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("CancelAllJ obs", 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
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14705
by: James | last post by:
Hello All, I have a stored procedure which will act like a main/controller script which will then invoke more stored procedures (~20). Basically, it looks something like below: -- start...
1
1858
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. ...
1
1764
by: SAN CAZIANO | last post by:
I have to insert a button in the left of all record in a table to print the current record, simply create a table and print it in the printer. anyone have an idea or there is a printer/report...
7
3193
by: Magnus Warker | last post by:
Hi, I want to traverse an (associative) array, starting from its current position, until a certain element is reached. Then, in certain cases, I want to be able to reset the current position of...
2
21934
by: Polly | last post by:
I'm trying to write the results of a query, a name, ID number, and date out to a notepad .txt file to print on a "legacy" printer. I get the output from the first 2 "write" lines over the...
3
1068
by: Bob | last post by:
I want to be able to cancel queries that take too long in a winforms app, yet it's not clear to me how to do this cleanly. I want to do it in a way that the server immediately stops execution, and...
1
1598
by: John | last post by:
Hi How can I cancel the current record that user has just inserted, changed a few fields and is still on it i.e. not saved? Thanks Regards
2
22102
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
3
1321
by: Oliver Nelson | last post by:
I have MapPoint working in Python, and I'm trying to cancel events on the map, but I can't seem to make that happen. I'm responding to the events successfully in my panel object. My code is like...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.