![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Below is the code I am trying to use in a console application, each time I run it I get an Management error Illegal Class error. I have traced the error to the \"Win32_Process\" line, apparently the wmi path is incorrect. Tried to run the app on both xp and vista with the same error. Could someone suggest how I might correct this wmi path variable??? 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.ThrowWithExt endedInfo(ManagementStat us errorCode) at System.Management.ManagementEventWatcher.WaitForNe xtEvent() 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.~ |
#3
| |||
| |||
|
#4
| |||
| |||
|
| Open an application to trigger an Event. |
|
"Henry" <atnorthend_SPAM_ (AT) hotmail (DOT) com> wrote in message news:3983A93E-E059-4635-9CAC-B9329D07715E (AT) microsoft (DOT) com... Below is the code I am trying to use in a console application, each time I run it I get an Management error Illegal Class error. I have traced the error to the \"Win32_Process\" line, apparently the wmi path is incorrect. Tried to run the app on both xp and vista with the same error. Could someone suggest how I might correct this wmi path variable??? 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.ThrowWithExt endedInfo(ManagementStat us errorCode) at System.Management.ManagementEventWatcher.WaitForNe xtEvent() 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. |
#5
| |||
| |||
|
|
Below is the code I am trying to use in a console application, each time I run it I get an Management error Illegal Class error. I have traced the error to the \"Win32_Process\" line, apparently the wmi path is incorrect. Tried to run the app on both xp and vista with the same error. Could someone suggest how I might correct this wmi path variable??? 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.ThrowWithExt endedInfo(ManagementStat us errorCode) at System.Management.ManagementEventWatcher.WaitForNe xtEvent() 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.~ |
#6
| |||
| |||
|
|
Well, I wish it was that easy, corrected the space as you suggested, here is the error... It really seems to be a problem with the watcher, but what do I know??? Henry Open an application to trigger an Event. Unhandled Exception: System.Management.ManagementException: Invalid class at System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStat us errorCode) at System.Management.ManagementEventWatcher.WaitForNe xtEvent() 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 . . . |
#7
| |||
| |||
|
|
[Willy doing WMI Stuff] 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 |
#8
| |||
| |||
|
|
On Apr 7, 8:58 pm, "Henry" <atnorthend_SP... (AT) hotmail (DOT) com> wrote: Below is the code I am trying to use in a console application, each time I run it I get an Management error Illegal Class error. I have traced the error to the \"Win32_Process\" line, apparently the wmi path is incorrect. Tried to run the app on both xp and vista with the same error. Could someone suggest how I might correct this wmi path variable??? 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.ThrowWithExt endedInfo(ManagementStat us errorCode) at System.Management.ManagementEventWatcher.WaitForNe xtEvent() 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.~ If you want to play around with WMI (find right syntax etc.) try to use WMI Creator: http://www.microsoft.com/downloads/d...displaylang=en Marian |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |