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

Get information from printers ...

Hi,

Sory for my messages but have next problems. For my first question as title
I received answer about how I can do program which catch PrintJob and I can
get data from that object.
I do program and run. I wanted print document but my appliaction raised
exception:

Error: Exception from HRESULT: 0x80042002.
Source: mscorlib
Stack Trace: at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode,
IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32
errorCode)
at System.Management.ManagementEventWatcher

I don't have any idea what is this, maybe I must configure framework or any
setting on system.
Application raised e xception but I just know that my program something do
:).

Next when I want run application appliation show me that message:

Error: Przekroczenie przydziału ( ang. "Przekroczenie"- Transgression,
"Przydziału": allowance, allotment, ration, assignation, issue )
Source: System.Management
Stack Trace: at
System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStatus
errorCode)
at System.Management.ManagementEventWatcher.Start()

I hope that I explain my problem and you will help me.
Thank's for all
Boniek
Nov 15 '05 #1
5 4096
Please post your code, more precisely the WMI query code, I guess there's
something wrong with the syntax.

Willy.

"Mortel" <mo****@poczta.onet.pl> wrote in message
news:bt**********@nemesis.news.tpi.pl...
Hi,

Sory for my messages but have next problems. For my first question as title I received answer about how I can do program which catch PrintJob and I can get data from that object.
I do program and run. I wanted print document but my appliaction raised
exception:

Error: Exception from HRESULT: 0x80042002.
Source: mscorlib
Stack Trace: at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32
errorCode)
at System.Management.ManagementEventWatcher

I don't have any idea what is this, maybe I must configure framework or any setting on system.
Application raised e xception but I just know that my program something do
:).

Next when I want run application appliation show me that message:

Error: Przekroczenie przydziału ( ang. "Przekroczenie"- Transgression,
"Przydziału": allowance, allotment, ration, assignation, issue )
Source: System.Management
Stack Trace: at
System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStatus errorCode)
at System.Management.ManagementEventWatcher.Start()

I hope that I explain my problem and you will help me.
Thank's for all
Boniek

Nov 15 '05 #2
OK I send my code in class, which workpublic abstract class PrinterInfoDetails{ public static bool FinishWork = false; public static void GetDetails(){ ManagementEventWatcher watcher = new ManagementEventWatcher( new WqlEventQuery("__InstanceCreationEvent")); MyHandler handler = new MyHandler(); watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived); try { watcher.Start(); try { while( !FinishWork ) { watcher.WaitForNextEvent(); Application.DoEvents(); } } finally { //Stop watching watcher.Stop(); } } catch (ManagementException e) { string str = ""; str += "ErrorCode " + e.ErrorCode +"\n"+ "Message " + e.Message +"\n"+ "Source " + e.Source +"\n"; if (e.ErrorInformation != null) //extended error object str += "Extended Description : " + e.ErrorInformation["Description"]; MessageBox.Show(str); }}public class MyHandler { private PrinterLogs printerLogs = new PrinterLogs(); public void Arrived(object sender, EventArrivedEventArgs e) { string className = ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"].ToString(); if( className == "Win32_PrintJob" ) { string owner = ((ManagementObject)e.NewEvent).Properties["Owner"].Value.ToString(); UInt32 count = (UInt32)((ManagementObject)e.NewEvent).Properties["TotalPages"].Value; printerLogs.AddPrinterJobInfo( count, owner ); } } }}
Nov 15 '05 #3
The event query needs a polling interval (within clause). Change your code like this: public static void GetDetails() { WqlEventQuery q = new WqlEventQuery(); { q.EventClassName = "__InstanceCreationEvent"; q.Condition = @"TargetInstance ISA 'Win32_PrintJob'"; q.WithinInterval = new TimeSpan(0,0,10); ManagementEventWatcher watcher = new ManagementEventWatcher(q); MyHandler handler = new MyHandler(); ..... }Willy."Mortel" <mo****@poczta.onet.pl> wrote in message news:bt**********@atlantis.news.tpi.pl...OK I send my code in class, which work public abstract class PrinterInfoDetails{ public static bool FinishWork = false; public static void GetDetails(){ ManagementEventWatcher watcher = new ManagementEventWatcher( new WqlEventQuery("__InstanceCreationEvent")); MyHandler handler = new MyHandler(); watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived); try { watcher.Start(); try { while( !FinishWork ) { watcher.WaitForNextEvent(); Application.DoEvents(); } } finally { //Stop watching watcher.Stop(); } } catch (ManagementException e) { string str = ""; str += "ErrorCode " + e.ErrorCode +"\n"+ "Message " + e.Message +"\n"+ "Source " + e.Source +"\n"; if (e.ErrorInformation != null) //extended error object str += "Extended Description : " + e.ErrorInformation["Description"]; MessageBox.Show(str); }}public class MyHandler { private PrinterLogs printerLogs = new PrinterLogs(); public void Arrived(object sender, EventArrivedEventArgs e) { string className = ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"].ToString(); if( className == "Win32_PrintJob" ) { string owner = ((ManagementObject)e.NewEvent).Properties["Owner"].Value.ToString(); UInt32 count = (UInt32)((ManagementObject)e.NewEvent).Properties["TotalPages"].Value; printerLogs.AddPrinterJobInfo( count, owner ); } } }}
Nov 15 '05 #4
Thank's. It work I mean no error and I have my event. Next my qustion is:

public class MyHandler {

private PrinterLogs printerLogs = new PrinterLogs();

public void Arrived(object sender, EventArrivedEventArgs e)

{

string className = ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"].ToString();

if( className == "Win32_PrintJob" )

{

string owner = ((ManagementObject)e.NewEvent).Properties["Owner"].Value.ToString();

UInt32 count = (UInt32)((ManagementObject)e.NewEvent).Properties["TotalPages"].Value;

printerLogs.AddPrinterJobInfo( count, owner );

}

}

}

When I have get className from target of event I received errors that that properties not found. NewEvent is not my PrinterJob ? How I can get information or that object ?

Użytkownik "Willy Denoyette [MVP]" <wi*************@pandora.be> napisał w wiadomości news:e$**************@TK2MSFTNGP10.phx.gbl...
The event query needs a polling interval (within clause). Change your code like this: public static void GetDetails() { WqlEventQuery q = new WqlEventQuery(); { q.EventClassName = "__InstanceCreationEvent"; q.Condition = @"TargetInstance ISA 'Win32_PrintJob'"; q.WithinInterval = new TimeSpan(0,0,10); ManagementEventWatcher watcher = new ManagementEventWatcher(q); MyHandler handler = new MyHandler(); ..... } Willy.
Nov 15 '05 #5
The classname is always a Win32_PrintJob, try this...

public void Arrived(object sender, EventArrivedEventArgs e)

{

string owner = null;
int count = 0;

foreach(PropertyData pd in e.NewEvent.Properties)

{

ManagementBaseObject mbo = null;
if(( mbo = pd.Value as ManagementBaseObject) != null) {
owner = mbo.Properties["owner"].Value.ToString();
count = (int)mbo.Properties["TotalPages"].Value;
}
}

.....

Willy.

"Mortel" <mo****@poczta.onet.pl> wrote in message news:bt**********@atlantis.news.tpi.pl...

Thank's. It work I mean no error and I have my event. Next my qustion is:

public class MyHandler {

private PrinterLogs printerLogs = new PrinterLogs();

public void Arrived(object sender, EventArrivedEventArgs e)

{

string className = ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"].ToString();

if( className == "Win32_PrintJob" )

{

string owner = ((ManagementObject)e.NewEvent).Properties["Owner"].Value.ToString();

UInt32 count = (UInt32)((ManagementObject)e.NewEvent).Properties["TotalPages"].Value;

printerLogs.AddPrinterJobInfo( count, owner );

}

}

}

When I have get className from target of event I received errors that that properties not found. NewEvent is not my PrinterJob ? How I can get information or that object ?

Użytkownik "Willy Denoyette [MVP]" <wi*************@pandora.be> napisał w wiadomości news:e$**************@TK2MSFTNGP10.phx.gbl...
The event query needs a polling interval (within clause). Change your code like this: public static void GetDetails() { WqlEventQuery q = new WqlEventQuery(); { q.EventClassName = "__InstanceCreationEvent"; q.Condition = @"TargetInstance ISA 'Win32_PrintJob'"; q.WithinInterval = new TimeSpan(0,0,10); ManagementEventWatcher watcher = new ManagementEventWatcher(q); MyHandler handler = new MyHandler(); ..... } Willy.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ADE | last post by:
I have three printers that are printing a lot of material each day (Epson Printers) I would like to be able to after I hit the Print Button and Before the Print Preview have a Python Tkinter...
5
by: Aaron_TekRecycle.com | last post by:
Someone must have done this before?!? I have VBS code that will Enumerate all the Printers in the AD and Add the Printer Connection to the client... I'm just not a web developer so I need some...
1
by: Vanessa | last post by:
Hi, I'm trying to loop through all the printers in my computer system using WMI. However, I found out that it doesn't really get the correct number of printers in my system. I have 16...
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
1
by: Mortel | last post by:
Hi, How I can get information from printer about count of copy pages, who's print pages etc. I want monitoring printers and save that information to file log. Maybe printer has any events to do...
1
by: Mortel | last post by:
Hi, How I can get information from printer about count of copy pages, who's print pages etc. I want monitoring printers and save that information to file log. Maybe printer has any events to do...
7
by: trint | last post by:
How can I add all the network printers to a combobox? Thanks, Trint
3
by: Morten Fagermoen | last post by:
Hi! I use the code below to find the printers connected to the local computer. How can I get the "Location" and "Description" information from the printers I have connected? Public Sub...
0
by: Ravigwipro | last post by:
Hi, I m able to get the printers object to know what are the printers had been installed and all. here my requirement is i have to write a data from VB to MS Word. for the page setup i have to...
4
by: Frank Rizzo | last post by:
I basically need a list of printers that's returned by the Find Printers dialog ( http://www.sqleffects.com/mystuff/findPrinters.png ). I've tried the path of DirectoryEntry entry = new...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.