using wmi, ldap vs inbuilt objects

borris83

Member
Joined
Apr 30, 2009
Messages
23
Programming Experience
Beginner
Looks like there are a few things which can be accomplished by two ways...

For things like querying registry, eventlog etc I make a connection to wmi services and then query for information.. But for querying event log there is an object called geteventlogs and also there is a class for registry as well..

But I want to know if using wmi has any drawbacks because I just finished coding an application entirely using wmi connections without knowing that I can use geteventlogs()

For eg, both the codes given below run fine and give me the same output:

Code 1:
VB.NET:
 Dim objeventlog, objlog, objentry As New Object
        Dim strcomputer As String = "." 'replace the '.' with computer name for remote computer
     
        objeventlog = EventLog.GetEventLogs(strcomputer)

        For Each objlog In objeventlog
            For Each entry As Object In objlog.entries
                If entry.timewritten = "6/19/2010 11:58:04 AM" And entry.entrytype = 1 Then
                    MessageBox.Show(entry.message)
                End If
            Next
        Next

Code 2:

VB.NET:
   Dim objwmiservice, objlog, collog As Object
        Dim strcomputer As String = "." 'replace the '.' with computer name for remote computer
        objwmiservice = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2")
        collog = objwmiservice.execquery("select * from win32_ntlogevent where timewritten = '20100619115804.000000+330' and type = 'error'")

        For Each objlog In collog
            MessageBox.Show(objlog.message)
        Next

I just want to make sure that my application won't run into problem in the future, because I am using the type in Code 2
 
Back
Top