473,804 Members | 3,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("winm gmts:{impersona tionLevel=imper sonate}!\\.\roo t\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEven t Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529 .000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.E xecQuery(strque ry, "WQL",
wbemFlagReturnI mmediately + wbemFlagForward Only)

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

Nov 21 '05 #1
2 2110
Hi,

Here is how I would do that.

Dim moReturn As Management.Mana gementObjectCol lection

Dim moSearch As Management.Mana gementObjectSea rcher

Dim mo As Management.Mana gementObject

moSearch = New Management.Mana gementObjectSea rcher("Select * from
Win32_NTLogEven t Where " & _

"Logfile ='Application' and Type = 'Warning' and TimeWritten
='200509161435 29.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****@missour i.edu> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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("winm gmts:{impersona tionLevel=imper sonate}!\\.\roo t\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEven t Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529 .000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.E xecQuery(strque ry, "WQL",
wbemFlagReturnI mmediately + wbemFlagForward Only)

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.Mana gementObjectCol lection

Dim moSearch As Management.Mana gementObjectSea rcher

Dim mo As Management.Mana gementObject

moSearch = New Management.Mana gementObjectSea rcher("Select * from
Win32_NTLogEven t Where " & _

"Logfile ='Application' and Type = 'Warning' and TimeWritten
>='200509161435 29.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****@missour i.edu> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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("winm gmts:{impersona tionLevel=imper sonate}!\\.\roo t\cimv2")

Dim colEvents As Collection

strquery = "Select * from Win32_NTLogEven t Where Logfile =
'Application' and Type = 'Warning' and TimeWritten >=
'20050916143529 .000000-300'"
'''the next line fails: Specified cast is not valid.
colEvents = objWMIService.E xecQuery(strque ry, "WQL",
wbemFlagReturnI mmediately + wbemFlagForward Only)

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
2521
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
2634
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 short "On this date in Disney history....<event>" on my main web page. Basically, if someone goes to my web page, they'll automatically see this if there is an event that occurred on this day. So, my problem is... how do I create an SQL database...
2
2548
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 very, very slow as the number of records grows - somewhere in the number of 5,000,000. I imagine queries are much faster but am not quite sure if queries will do the trick. My problem:
0
3417
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 11:51:51 -0700 Local: Tues, Aug 16 2005 2:51 pm Subject: Query Eventlog by Timewritten field. Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
3
1846
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 events that occur
1
3863
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 execute the following query in Access not all records that fit the condition are returned, and when I run this same query in SQL Server all the records I want are retrieved. The query is:
21
1623
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 different events to a user and if he will attend the event or not (or hasn't filled it in yet) the returned result could be something like: event.id attendees.user_id attendee.present
14
2224
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, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5' OR Events.Category LIKE '6' OR Events.Category LIKE '7' OR Events.Category LIKE '8' OR...
1
1255
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, which has an event id and a group type id, which refers to another table which stores the names of various different types of events. What I want to do is select all the events that have a particular group type id and are current events (i.e. the...
1
1337
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 clearly: I have data in database as follows: I have a table with time slots (Slots): SlotID Slot ================= 1 9-9.30 2 9.30-10
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.