473,795 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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..

ManagementObjec tSearcher searcher =new ManagementObjec tSearcher("SELE CT * FROM Win32_PrintJob ");

try
{
foreach (ManagementObje ct queryObj in searcher.Get())
{
string path = "C:/MYFILE.txt";//logged to this file
FileStream fileStream = new FileStream(path , FileMode.Append , FileAccess.Writ e, FileShare.None) ;
{
using (StreamWriter streamWriter = new StreamWriter(fi leStream))
{
streamWriter.Wr iteLine("-----------------------------------");
streamWriter.Wr iteLine("Win32_ PrintJob instance");
streamWriter.Wr iteLine("-----------------------------------");
streamWriter.Wr iteLine("Descri ption: {0}", queryObj["Descriptio n"]);
streamWriter.Wr iteLine("Docume nt:{0}",queryOb j["Document"]);
streamWriter.Wr iteLine("JobId: {0}", queryObj["JobId"]);
streamWriter.Wr iteLine("JobSta tus: {0}", queryObj["JobStatus"]);
streamWriter.Wr iteLine("Name: {0}", queryObj["Name"]);
streamWriter.Wr iteLine("Owner: {0}", queryObj["Owner"]);
streamWriter.Wr iteLine("PagesP rinted: {0}", queryObj["PagesPrint ed"]);
streamWriter.Wr iteLine("PrintP rocessor: {0}", queryObj["PrintProcessor "]);
streamWriter.Wr iteLine("Priori ty: {0}", queryObj["Priority"]);
streamWriter.Wr iteLine("Size: {0}", queryObj["Size"]);
streamWriter.Wr iteLine("TimeSu bmitted: {0}", queryObj["TimeSubmit ted"]);
streamWriter.Wr iteLine("TotalP ages: {0}", queryObj["TotalPages "]);
}
}


}

}
catch (ManagementExce ption me)
{

Console.WriteLi ne(me.Message.T oString());
Console.ReadLin e();
}
...
...Thanks in advance.....
Jun 13 '07 #1
1 2454
r035198x
13,262 MVP
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..

ManagementObjec tSearcher searcher =new ManagementObjec tSearcher("SELE CT * FROM Win32_PrintJob ");

try
{
foreach (ManagementObje ct queryObj in searcher.Get())
{
string path = "C:/MYFILE.txt";//logged to this file
FileStream fileStream = new FileStream(path , FileMode.Append , FileAccess.Writ e, FileShare.None) ;
{
using (StreamWriter streamWriter = new StreamWriter(fi leStream))
{
streamWriter.Wr iteLine("-----------------------------------");
streamWriter.Wr iteLine("Win32_ PrintJob instance");
streamWriter.Wr iteLine("-----------------------------------");
streamWriter.Wr iteLine("Descri ption: {0}", queryObj["Descriptio n"]);
streamWriter.Wr iteLine("Docume nt:{0}",queryOb j["Document"]);
streamWriter.Wr iteLine("JobId: {0}", queryObj["JobId"]);
streamWriter.Wr iteLine("JobSta tus: {0}", queryObj["JobStatus"]);
streamWriter.Wr iteLine("Name: {0}", queryObj["Name"]);
streamWriter.Wr iteLine("Owner: {0}", queryObj["Owner"]);
streamWriter.Wr iteLine("PagesP rinted: {0}", queryObj["PagesPrint ed"]);
streamWriter.Wr iteLine("PrintP rocessor: {0}", queryObj["PrintProcessor "]);
streamWriter.Wr iteLine("Priori ty: {0}", queryObj["Priority"]);
streamWriter.Wr iteLine("Size: {0}", queryObj["Size"]);
streamWriter.Wr iteLine("TimeSu bmitted: {0}", queryObj["TimeSubmit ted"]);
streamWriter.Wr iteLine("TotalP ages: {0}", queryObj["TotalPages "]);
}
}


}

}
catch (ManagementExce ption me)
{

Console.WriteLi ne(me.Message.T oString());
Console.ReadLin e();
}
...
...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
2993
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 "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
2
4454
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 */ #include <time.h>
1
1564
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 parsying to
4
3679
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 haven't decided what the best way to do this is because I don't have much experience with generating printable forms. Early on I knew one of my modules would need to print a clear report so I used the open source SharpPDF library to generate the...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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
10439
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
10215
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...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.