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

WMI query for events

This code snippet fails with 'Specified cast is not valid' when running
the query to get application warning events in the last 10 days...

What am I doing wrong?
HankC
Dim objWMIService As Object

objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEvent Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529.000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.ExecQuery(strquery, "WQL",
wbemFlagReturnImmediately + wbemFlagForwardOnly)

Dim objEvent As Object
For Each objEvent In colEvents
TextBox1.Text = TextBox1.Text & objEvent.Type & vbVrLf
Next
End If

Nov 21 '05 #1
2 2077
Hi,

Here is how I would do that.

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_NTLogEvent Where " & _

"Logfile ='Application' and Type = 'Warning' and TimeWritten
='20050916143529.000000-300'")
moReturn = moSearch.Get

For Each mo In moReturn

Dim strOut As String

strOut = String.Format("Date {0} Message {1}", mo("TimeWritten"),
mo("Message"))

Trace.WriteLine(strOut)

Next

Ken

-------------------

"HankC" <cl****@missouri.edu> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... This code snippet fails with 'Specified cast is not valid' when running
the query to get application warning events in the last 10 days...

What am I doing wrong?
HankC
Dim objWMIService As Object

objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEvent Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529.000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.ExecQuery(strquery, "WQL",
wbemFlagReturnImmediately + wbemFlagForwardOnly)

Dim objEvent As Object
For Each objEvent In colEvents
TextBox1.Text = TextBox1.Text & objEvent.Type & vbVrLf
Next
End If

Nov 21 '05 #2

Ken Tucker [MVP] wrote:
Hi,

Here is how I would do that.

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_NTLogEvent Where " & _

"Logfile ='Application' and Type = 'Warning' and TimeWritten
>='20050916143529.000000-300'")


moReturn = moSearch.Get

For Each mo In moReturn

Dim strOut As String

strOut = String.Format("Date {0} Message {1}", mo("TimeWritten"),
mo("Message"))

Trace.WriteLine(strOut)

Next

Ken

-------------------

"HankC" <cl****@missouri.edu> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
This code snippet fails with 'Specified cast is not valid' when running
the query to get application warning events in the last 10 days...

What am I doing wrong?
HankC
Dim objWMIService As Object

objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEvent Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529.000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.ExecQuery(strquery, "WQL",
wbemFlagReturnImmediately + wbemFlagForwardOnly)

Dim objEvent As Object
For Each objEvent In colEvents
TextBox1.Text = TextBox1.Text & objEvent.Type & vbVrLf
Next
End If


Thanks, Ken. That did the trick...

Nov 21 '05 #3

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

Similar topics

7
by: Joel Thornton | last post by:
I'm having much difficulty figuring out how to write the following query. Please help! I have this table: Event EventId int Primary Key PatientId int SeverityLevel int
2
by: Dan | last post by:
Hi all! I am creating a Disney "Today in History" database, and so far have about 300 entries in it. Well, my Access database is great, and my Frontpage form is great, but I want to include a...
2
by: Willem | last post by:
Hi there, I'm sort of new with doing much record manipulation with queries. Up till now I've been programming VBA and doing record looping to get my results. This works fine but tends to get...
0
by: hismail | last post by:
1. hism...@dot-solution.net Aug 16, 2:51 pm show options Newsgroups: microsoft.public.vb.general.discussion From: hism...@dot-solution.net - Find messages by this author Date: 16 Aug 2005...
3
by: XavierX | last post by:
Hi, I am trying to create a web page that outputs a list of data from a join on 2 tables. The Tables: PANEL - A list of possible panel numbers PANELID - Primary key, EVENTS - List of...
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
21
by: Tarscher | last post by:
Hi all, I have events containing attendees (events has many attendees). The attendee table tells whether a user will attend the event or not. I want to build a query that returns all the...
14
by: xoozlez | last post by:
Hi there, I have a registration form where I like to filter out the past events of 2007. This is the code I am using : strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd,...
1
pezholio
by: pezholio | last post by:
Hi, I've got two tables, one called events, which has an id field (eventid), a name field (eventname), a start date (datefrom) and an end date (date to), and another called events_to_grouptype,...
1
by: milecimm | last post by:
Hi, I'm binding a sqldtatasource to a gridview to obtain some calculations from the data. However something is wrong for the query because I know the calculations are wrong. I hope I can explain...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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.