473,410 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

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 10636
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 StringCollection GetPrintersCollection()
{
StringCollection printerNameCollection = new StringCollection();
string searchQuery = "SELECT * FROM Win32_Printer";
ManagementObjectSearcher searchPrinters =
new ManagementObjectSearcher(searchQuery);
ManagementObjectCollection printerCollection = searchPrinters.Get();
foreach(ManagementObject printer in printerCollection)
{
printerNameCollection.Add(printer.Properties["Name"].Value.ToString());
}
return printerNameCollection;
}
Using this printer name, we can fetch the print job collection by using the
following method:
public static StringCollection GetPrintJobsCollection(string printerName)
{
StringCollection printJobCollection = new StringCollection();
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*/
ManagementObjectSearcher searchPrintJobs =
new ManagementObjectSearcher(searchQuery);
ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
foreach(ManagementObject prntJob in prntJobCollection)
{
System.String jobName = prntJob.Properties["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(splitArr)[0];
string documentName = prntJob.Properties["Document"].Value.ToString();
if(String.Compare(prnterName, printerName, true) == 0)
{
printJobCollection.Add(documentName);
}
}
return printJobCollection;
}
The query "SELECT * FROM Win32_PrintJob" can also be used as "SELECT * FROM
Win32_PrintJob WHERE Name like '"+ printerName.Replace("\", "\\") +"%'". 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(string printerName, int printJobID)
{
bool isActionPerformed = false;
string searchQuery = "SELECT * FROM Win32_PrintJob";
ManagementObjectSearcher searchPrintJobs =
new ManagementObjectSearcher(searchQuery);
ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
foreach(ManagementObject prntJob in prntJobCollection)
{
System.String jobName = prntJob.Properties["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(splitArr)[0];
int prntJobID = Convert.ToInt32(jobName.Split(splitArr)[1]);
string documentName = prntJob.Properties["Document"].Value.ToString();
if(String.Compare(prnterName, printerName, true) == 0)
{
if(prntJobID == printJobID)
{
prntJob.InvokeMethod("Pause", null);
isActionPerformed = true;
break;
}
}
}
return isActionPerformed;
}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.InvokeMethod("Resume", null);Win32_PrintJob 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 isActionPerformed = false;
string searchQuery = "SELECT * FROM Win32_PrintJob";
ManagementObjectSearcher searchPrintJobs =
new ManagementObjectSearcher(searchQuery);
ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
foreach(ManagementObject prntJob in prntJobCollection)
{
System.String jobName = prntJob.Properties["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(splitArr)[0];
int prntJobID = Convert.ToInt32(jobName.Split(splitArr)[1]);
string documentName = prntJob.Properties["Document"].Value.ToString();
if(String.Compare(prnterName, printerName, true) == 0)
{
if(prntJobID == printJobID)
{
//performs a action similar to the cancel
//operation of windows print console
prntJob.Delete();
isActionPerformed = true;
break;
}
}
}
return isActionPerformed;
}
HTH
--

Bob

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

"Michael Beck" <Mi***********@pacbell.net> wrote in message
news:ea**************@TK2MSFTNGP15.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
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? ...
1
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(); //...
3
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...
3
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...
6
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...
11
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...
3
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...
3
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...
3
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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...
0
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,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.