468,107 Members | 1,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

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 2075
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

Post your reply

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

By using this site, you agree to our Privacy Policy and Terms of Use.