473,790 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tracking a print job

I need to select one of about 15 printers, which I have been able to do.
Then I need to set that printer as the printer to use, run a Crystal Reports
reports, and track if/when the printing job completes.

Is there a book or article that can help me?

If it is fairly easy, can anyone sen me some code that will get me started.

TIA,

Mike

Nov 21 '05 #1
1 10774
The below code I used when i did a similar thing once. It is in C# I know
but not difficult to translate to VB.Net OR put it in a class in your
solution and make it available to your VB.Net project. I can't post my
previous code because I don't have it anymore!
To get a list of printers:

public static StringCollectio n GetPrintersColl ection()
{
StringCollectio n printerNameColl ection = new StringCollectio n();
string searchQuery = "SELECT * FROM Win32_Printer";
ManagementObjec tSearcher searchPrinters =
new ManagementObjec tSearcher(searc hQuery);
ManagementObjec tCollection printerCollecti on = searchPrinters. Get();
foreach(Managem entObject printer in printerCollecti on)
{
printerNameColl ection.Add(prin ter.Properties["Name"].Value.ToString ());
}
return printerNameColl ection;
}
Using this printer name, we can fetch the print job collection by using the
following method:
public static StringCollectio n GetPrintJobsCol lection(string printerName)
{
StringCollectio n printJobCollect ion = new StringCollectio n();
string searchQuery = "SELECT * FROM Win32_PrintJob" ;

/*searchQuery can also be mentioned with where Attribute,
but this is not working in Windows 2000 / ME / 98 machines
and throws Invalid query error*/
ManagementObjec tSearcher searchPrintJobs =
new ManagementObjec tSearcher(searc hQuery);
ManagementObjec tCollection prntJobCollecti on = searchPrintJobs .Get();
foreach(Managem entObject prntJob in prntJobCollecti on)
{
System.String jobName = prntJob.Propert ies["Name"].Value.ToString ();

//Job name would be of the format [Printer name], [Job ID]
char[] splitArr = new char[1];
splitArr[0] = Convert.ToChar( ",");
string prnterName = jobName.Split(s plitArr)[0];
string documentName = prntJob.Propert ies["Document"].Value.ToString ();
if(String.Compa re(prnterName, printerName, true) == 0)
{
printJobCollect ion.Add(documen tName);
}
}
return printJobCollect ion;
}
The query "SELECT * FROM Win32_PrintJob" can also be used as "SELECT * FROM
Win32_PrintJob WHERE Name like '"+ printerName.Rep lace("\", "\\") +"%'". But
the query with WHICH attribute caused problems in my system which was
running Windows 2000, but ran smooth in Windows XP machines. So currently, I
am making a loop through all the print jobs and identify print jobs for that
particular printer.

Now, let's see how to manage these print jobs. The print console provided by
Windows allows us to Pause, Resume and Cancel print jobs. It also allows to
set priority for a print job. Using WMI, we can perform Pause, Resume and
Cancel, but it doesn't provide any method for changing the priority level.

The following code depicts how to pause a print job:

public static bool PausePrintJob(s tring printerName, int printJobID)
{
bool isActionPerform ed = false;
string searchQuery = "SELECT * FROM Win32_PrintJob" ;
ManagementObjec tSearcher searchPrintJobs =
new ManagementObjec tSearcher(searc hQuery);
ManagementObjec tCollection prntJobCollecti on = searchPrintJobs .Get();
foreach(Managem entObject prntJob in prntJobCollecti on)
{
System.String jobName = prntJob.Propert ies["Name"].Value.ToString ();
//Job name would be of the format [Printer name], [Job ID]
char[] splitArr = new char[1];
splitArr[0] = Convert.ToChar( ",");
string prnterName = jobName.Split(s plitArr)[0];
int prntJobID = Convert.ToInt32 (jobName.Split( splitArr)[1]);
string documentName = prntJob.Propert ies["Document"].Value.ToString ();
if(String.Compa re(prnterName, printerName, true) == 0)
{
if(prntJobID == printJobID)
{
prntJob.InvokeM ethod("Pause", null);
isActionPerform ed = true;
break;
}
}
}
return isActionPerform ed;
}By invoking the Pause method, we can pause the print job. Similar approach
is required for resuming the print job. Just we need to invoke the Resume
method.

prntJob.InvokeM ethod("Resume", null);Win32_Pri ntJob WMI_CLASS provides
methods to pause and resume a print job. But it doesn't provide any method
for canceling the print job. To cancel the print job, you need to just
delete the management object.

public static bool CancelPrintJob( string printerName, int printJobID)
{
bool isActionPerform ed = false;
string searchQuery = "SELECT * FROM Win32_PrintJob" ;
ManagementObjec tSearcher searchPrintJobs =
new ManagementObjec tSearcher(searc hQuery);
ManagementObjec tCollection prntJobCollecti on = searchPrintJobs .Get();
foreach(Managem entObject prntJob in prntJobCollecti on)
{
System.String jobName = prntJob.Propert ies["Name"].Value.ToString ();
//Job name would be of the format [Printer name], [Job ID]
char[] splitArr = new char[1];
splitArr[0] = Convert.ToChar( ",");
string prnterName = jobName.Split(s plitArr)[0];
int prntJobID = Convert.ToInt32 (jobName.Split( splitArr)[1]);
string documentName = prntJob.Propert ies["Document"].Value.ToString ();
if(String.Compa re(prnterName, printerName, true) == 0)
{
if(prntJobID == printJobID)
{
//performs a action similar to the cancel
//operation of windows print console
prntJob.Delete( );
isActionPerform ed = true;
break;
}
}
}
return isActionPerform ed;
}
HTH
--

Bob

--------------------------------------
I'll have a B please Bob.

"Michael Beck" <Mi***********@ pacbell.net> wrote in message
news:ea******** ******@TK2MSFTN GP15.phx.gbl...
I need to select one of about 15 printers, which I have been able to do.
Then I need to set that printer as the printer to use, run a Crystal
Reports
reports, and track if/when the printing job completes.

Is there a book or article that can help me?

If it is fairly easy, can anyone sen me some code that will get me
started.

TIA,

Mike

Nov 21 '05 #2

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

Similar topics

1
2762
by: marslee | last post by:
I am a php newbie. I would like to count how many times a user visit a webpage. I know session tracking should be used, but where i put the code? Is it inside the html that the user visit? session_start(); if (!IsSet($page_number)) $page_number = 1; print("You have now visited $page_number"); print(" of pages <br />");
1
2302
by: Skeleton Man | last post by:
Hi, I have a chat script which I added very basic bandwidth tracking to as follows: ob_start(); print "this is some output!"; print "this is more output!"; $bytes = ob_get_length(); // Amount of bandwidth used ob_end_flush();
3
2818
by: Kyle Friesen via AccessMonster.com | last post by:
Mike, I have databse that creates a "tracking number" based on the selections made on the form via concatenating. At the end of the tracking number, I need a two digit (01-99) sequence number by product group for each customer. Hpw do I do this without creating a table for each customer and each product group with autonumbers. For example based on the entries in this sample, the desired result would be: Customer Business Unit Tracking...
3
1595
by: BW | last post by:
Has anyone attempted writing a print-tracking application in VB.Net? I'd like it to run as an active service on the server and monitor all printjobs. I'd like to write it myself but am not sure where to start. The app will reside on SBS2003. Can someone point me in the right direction on how to go about writing this? bw
6
3415
by: DFS | last post by:
One of my systems grew exponentially - from 13mb to 43mb - after adding some 10 temp tables (with no data), a new form, and about a thousand lines of code. The .mdb has mostly table links, lots of forms and queries, and a good bit of code overall. But 43mb is totally unreasonble. I can't figure out where the problem is occurring. It was fine for a long time. I even created a new file and imported the objects and it blew back up to...
11
30727
by: SKBodner | last post by:
Hello, I'm stumped and I'm hoping someone could help me figure out the best way to track daily attendance for the next 6-4 months. I have a list of 80 or so participants who should be attended training on a daily basis and am tracking if they attended, have an unexcused absence, or are absence with an excuse. At the end of the month, I plan to print out reports on those who have missed more than one day with an unexcused absence. My...
3
2519
by: =?Utf-8?B?R3JhaGFt?= | last post by:
I've added 2 tracking services to the wf runtime; one is the standard SqlTrackingService: trackingService = new SqlTrackingService(<trackingConnectionString>); <workflow Runtime>.AddService(trackingService); trackingService.IsTransactional = false; trackingService.UseDefaultProfile = true; This works just fine.
3
1579
by: Charles Abetz | last post by:
Hi all My problem is that I am creating a session file on the server when the user first visits my website, but when the user logs in i want to write to the file again with the timestamp and their userID. Code snipet if ($core->cookie(-name=>'ChasSession') eq "") { if ($sID eq "") { $sID = int(rand 1e9);
3
1410
by: ashishbathini | last post by:
firstly i want to thatn all you guys for the help on the sorting program i have a problem that i tried but 'm unable to solve ... u guys helped a lot in my previous post .. so please help me now .. 'm using windows
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5424
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2910
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.