PlanetMPs.com

Main Menu Betas WMI Code Snipppets More Detailed WMI Code Samples Usage Examples WMI And HTML Controls Additional Tools IDE Examples Using WMI Net IDE Examples Using WMI Book Reviews Technical Blogs Products Services Community News And Views Site Map Competitions In House Articles Submit An Article Newsgroups Forums About Us Tools Links Leisure Related Sites
Welcome To PlanetMPs.com
Core Building Blocks Of A ManagementPack:


        Dim classname
        Dim ns

        ns = "root\cimv2"
        classname = "Win32_Service"

        
        Set locator = CreateObject("WbemScripting.SWbemLocator")
        Set svc = locator.ConnectServer(".", ns)
        svc.Security_.AuthenticationLevel=6
        svc.Security_.ImpersonationLevel=3


        Set ws = CreateObject("WScript.Shell")
        Set fso = CreateObject("Scripting.FileSystemObject")

        If (fso.FileExists(ws.CurrentDirectory & "\" & classname & ".mdb") = True) Then
            fso.DeleteFile(ws.CurrentDirectory & "\" & classname & ".mdb")
        End If

        Set oa = CreateObject("Access.Application")
        oA.NewCurrentDatabase(ws.CurrentDirectory & "\" & classname & ".mdb", 12)
        oa.Visible = False

        Set db = oA.CurrentDb
        Set tb = CreateObject("DAO.TableDef.36")
        tb.Name = classname
        Set fld = tb.Fields.Create("ID", 3)
        tb.Fields.Append fld
        fld.AllowZeroLength = false
        set fld = nothing



        For Each obj In objs
            For Each prop In obj.Properties_
                Set fld = tb.Fields.Create(prop.Name, 12)
                tb.Fields.Append fld
                fld.AllowZeroLength = true
        	set fld = nothing
            Next
            Exit For
        Next

        db.TableDefs.Append(tbl)
         
        Set tbl = Nothing
        

        Set rs = db.OpenRecordset("Select * From " & classname)


        For Each obj In objs
            rs.AddNew()
            For Each prop In obj.Properties_
                rs.Fields(prop.Name).Value = CStr(GetValue(prop.Name, obj))
            Next
            rs.Fields("ID").Value = x
            rs.Update()
            x = x + 1
        Next

        Set rs = Nothing
        oa.Visible = true


    Function GetValue(ByVal name, ByVal obj)

        Dim pos
        Dim tempstr
        Dim tName


        tempstr = obj.GetObjectText_
        tName = name & " = "
        pos = InStr(tempstr, tName)
        If pos Then
            pos = pos + Len(name & " = ")
            tempstr = Mid(tempstr, pos, Len(tempstr))
            pos = InStr(tempstr, ";")
            tempstr = Mid(tempstr, 1, pos - 1)
            tempstr = Replace(tempstr, Chr(34), "")
            tempstr = Replace(tempstr, "{", "")
            tempstr = Replace(tempstr, "}", "")
            If Len(tempstr) > 13 And obj.Properties_(name).CIMType = 101 Then
                tempstr = Mid(tempstr, 5, 2) & "/" & _
                          Mid(tempstr, 7, 2) & "/" & _
                          Mid(tempstr, 1, 4) & " " & _
                          Mid(tempstr, 9, 2) & ":" & _
                          Mid(tempstr, 11, 2) & ":" & _
                          Mid(tempstr, 13, 2)
            End If
            GetValue = tempstr
        Else
            GetValue = ""
        End If

    End Function