Get information from printers ...

  • Thread starter Thread starter Mortel
  • Start date Start date
M

Mortel

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.ThrowExceptionForHR(Int32 errorCode,
IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(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.ThrowWithExtendedInfo(ManagementStatus
errorCode)
at System.Management.ManagementEventWatcher.Start()

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

Willy.
 
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 ); } } }}
 
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" <[email protected]> wrote in message news:[email protected] 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 ); } } }}
 
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]" <[email protected]> napisa³ w wiadomo¶ci 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.
 
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.






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]" <[email protected]> napisa³ w wiadomo¶ci 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.
 
Back
Top