473,221 Members | 1,755 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,221 software developers and data experts.

problem creating a log while adding new print job using wmi and c#

HI,

i have created a windows service using wmi and c# for mantaining a log of all print jobs in the printing queue.It creates log of only those print jobs which are there when the service started.But i want it to create log of a newly added print job to the print queue when the service is running..can any one help please..my simple code is below..

ManagementObjectSearcher searcher =new ManagementObjectSearcher("SELECT * FROM Win32_PrintJob ");

try
{
foreach (ManagementObject queryObj in searcher.Get())
{
string path = "C:/MYFILE.txt";//logged to this file
FileStream fileStream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.None);
{
using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
streamWriter.WriteLine("-----------------------------------");
streamWriter.WriteLine("Win32_PrintJob instance");
streamWriter.WriteLine("-----------------------------------");
streamWriter.WriteLine("Description: {0}", queryObj["Description"]);
streamWriter.WriteLine("Document:{0}",queryObj["Document"]);
streamWriter.WriteLine("JobId: {0}", queryObj["JobId"]);
streamWriter.WriteLine("JobStatus: {0}", queryObj["JobStatus"]);
streamWriter.WriteLine("Name: {0}", queryObj["Name"]);
streamWriter.WriteLine("Owner: {0}", queryObj["Owner"]);
streamWriter.WriteLine("PagesPrinted: {0}", queryObj["PagesPrinted"]);
streamWriter.WriteLine("PrintProcessor: {0}", queryObj["PrintProcessor"]);
streamWriter.WriteLine("Priority: {0}", queryObj["Priority"]);
streamWriter.WriteLine("Size: {0}", queryObj["Size"]);
streamWriter.WriteLine("TimeSubmitted: {0}", queryObj["TimeSubmitted"]);
streamWriter.WriteLine("TotalPages: {0}", queryObj["TotalPages"]);
}
}


}

}
catch (ManagementException me)
{

Console.WriteLine(me.Message.ToString());
Console.ReadLine();
}
...
...Thanks in advance.....
Jun 13 '07 #1
1 2412
r035198x
13,262 8TB
HI,

i have created a windows service using wmi and c# for mantaining a log of all print jobs in the printing queue.It creates log of only those print jobs which are there when the service started.But i want it to create log of a newly added print job to the print queue when the service is running..can any one help please..my simple code is below..

ManagementObjectSearcher searcher =new ManagementObjectSearcher("SELECT * FROM Win32_PrintJob ");

try
{
foreach (ManagementObject queryObj in searcher.Get())
{
string path = "C:/MYFILE.txt";//logged to this file
FileStream fileStream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.None);
{
using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
streamWriter.WriteLine("-----------------------------------");
streamWriter.WriteLine("Win32_PrintJob instance");
streamWriter.WriteLine("-----------------------------------");
streamWriter.WriteLine("Description: {0}", queryObj["Description"]);
streamWriter.WriteLine("Document:{0}",queryObj["Document"]);
streamWriter.WriteLine("JobId: {0}", queryObj["JobId"]);
streamWriter.WriteLine("JobStatus: {0}", queryObj["JobStatus"]);
streamWriter.WriteLine("Name: {0}", queryObj["Name"]);
streamWriter.WriteLine("Owner: {0}", queryObj["Owner"]);
streamWriter.WriteLine("PagesPrinted: {0}", queryObj["PagesPrinted"]);
streamWriter.WriteLine("PrintProcessor: {0}", queryObj["PrintProcessor"]);
streamWriter.WriteLine("Priority: {0}", queryObj["Priority"]);
streamWriter.WriteLine("Size: {0}", queryObj["Size"]);
streamWriter.WriteLine("TimeSubmitted: {0}", queryObj["TimeSubmitted"]);
streamWriter.WriteLine("TotalPages: {0}", queryObj["TotalPages"]);
}
}


}

}
catch (ManagementException me)
{

Console.WriteLine(me.Message.ToString());
Console.ReadLine();
}
...
...Thanks in advance.....
1.) Please use code tags everytime when posting code.
2.)'ve moved yout thread to the more appropriate .NET forum.
Jun 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
1
by: napolpie | last post by:
----Messaggio originale---- Da: napolpie@tin.it Data: 3-mag-2007 10.02 A: <python-list@python.org> Ogg: problem with meteo datas Hello, I'm Peter and I'm new in python codying and I'm using...
4
by: sklett | last post by:
I've developed an ERP application that we use internally and works quite well. I receiving more and more requests from users to print various transactions, order forms, search results, etc. I...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.