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")
Set objs = svc.InstancesOf(classname, 48)
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
Set pi = xmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='ISO-8859-1'")
Set oRoot = xmlDoc.CreateElement("data")
xmlDoc.AppendChild(pi)
Dim oNode
Dim oNode1
Dim x As Integer = 0
Dim y As Integer = 0
For each obj in objs
Set oNode = xmlDoc.CreateNode(1, "" & Classname & "", "")
For Each prop In obj.Properties_
Set oNode1 = xmlDoc.CreateNode(1, prop.Name, "")
Dim oAtt As XmlAttribute = xmlDoc.CreateAttribute("NAME")
oAtt.InnerText = prop.Name
oNode1.Attributes.SetNamedItem(oAtt)
Set oAtt = xmlDoc.CreateAttribute("DATATYPE")
oAtt.InnerText = prop.Qualifiers_("CIMType").Value
oNode1.Attributes.SetNamedItem(oAtt)
Set oAtt = xmlDoc.CreateAttribute("SIZE")
oAtt.InnerText = "255"
oNode1.Attributes.SetNamedItem(oAtt)
Set oAtt = xmlDoc.CreateAttribute("VALUE")
oAtt.InnerText = GetValue(prop.Name, obj)
oNode1.Attributes.SetNamedItem(oAtt)
oNode.AppendChild(oNode1)
Next
oRoot.AppendChild(oNode)
Next
xmlDoc.AppendChild(oRoot)
Filename = ws.currentdirectory & "\" & Classname & "_Attribute.xml"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(Filename) = True) Then
fso.deleteFile(Filename)
End If
Set fso = Nothing
xmlDoc.Save Filename
Set xmlDoc = Nothing
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
|