Thanks
Henry
+++++++++++++++++++++++++++++++++++++++++++++++++++++
public static void WriteToEventLog()
{
WqlEventQuery DemoQuery = new
WqlEventQuery("_InstanceCreationEvent", new TimeSpan(0, 0, 1),
"TargetInstance isa \"Win32_Process\" ");
ManagementEventWatcher DemoWatcher = new
ManagementEventWatcher();
DemoWatcher.Query = DemoQuery;
DemoWatcher.Options.Timeout = new TimeSpan(0, 0, 30);
Console.WriteLine("Open an application to trigger an Event.");
ManagementBaseObject e = DemoWatcher.WaitForNextEvent();
EventLog DemoLog = new EventLog("Chap10Demo");
DemoLog.Source = "Chap10Demo";
String EventName =
((ManagementBaseObject)e["TargetInstance"])["Name"].ToString();
Console.WriteLine(EventName);
DemoLog.WriteEntry(EventName, EventLogEntryType.Information);
DemoWatcher.Stop();
}
+++++++++++++++++++++++++++++++Error follows
Open an application to trigger an Event.
Unhandled Exception: System.Management.ManagementException: Invalid class
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStat
us errorCode)
at System.Management.ManagementEventWatcher.WaitForNextEvent()
at ManagementEvents1.Program.WriteToEventLog() in
I:\Projects\ManagementEvent
s1\ManagementEvents1\Program.cs:line 29
at ManagementEvents1.Program.Main(String[] args) in
I:\Projects\ManagementEve
nts1\ManagementEvents1\Program.cs:line 14
Press any key to continue . . .
--
~
Most good judgment comes from experience.
Most experience comes from bad judgment.
~I'm leaning towards bad judgment.~
Notice the space at the end of ..
"TargetInstance isa \"Win32_Process\" ");
should be...
"TargetInstance isa \"Win32_Process\"");
Willy.
You always have the coolest WMI stuff handy. Have you written a FAQ on it
anywhere, or archived all your examples?
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins
Henry
>>>>
Open an application to trigger an Event.
Unhandled Exception: System.Management.ManagementException: Invalid class
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStat
us errorCode)
at System.Management.ManagementEventWatcher.WaitForNextEvent()
at ManagementEvents1.Program.WriteToEventLog() in
I:\Projects\ManagementEvent
s1\ManagementEvents1\Program.cs:line 29
at ManagementEvents1.Program.Main(String[] args) in
I:\Projects\ManagementEve
nts1\ManagementEvents1\Program.cs:line 14
Press any key to continue . . .
>>>>
"Willy Denoyette [MVP]" <willy.d...@telenet.be> wrote in message
news:ei#Q#0qeHH...@TK2MSFTNGP05.phx.gbl...
If you want to play around with WMI (find right syntax etc.) try to
use WMI Creator:
Marian
Sorry missed this one...
_InstanceCreationEvent
should be:
__InstanceCreationEvent
notice the double underscore!
Willy.
Chris, a have an archive of samples, I just have to clean them up and add some comments, I
will save some time to do this and keep you informed here.
As for the FAQ, I keep some inter-company kind of Knowledge Base articles, but I'm afraid I
can't publish them as they are, I will see what I can do to turn this stuff into some
publically available FAQ .
Willy.
Again Thanks
Henry
<majl...@gmail.com> wrote in message
news:1176192862.4...@d57g2000hsg.googlegroups.com...