473,396 Members | 1,775 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,396 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 2425
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...
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...

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.