The following is an example of using VB.Net and WMI:
You can download more of these examples from:
http://www.planetmps.com/
Private Sub Form_Load()
Dim l
Dim svc
Dim objs
Dim obj
Dim prop
Dim Name
Dim Value
Set l = CreateObject("WbemScripting.SwbemLocator")
Set svc = l.ConnectServer(".", "\root\cimv2")
Set objs = svc.InstancesOf("Win32_Bios")
For Each obj In objs
For Each prop In obj.Properties_
Name = prop.Name
Value = GetValue(prop.Name, obj)
Debug.Print Name & " " & Value
Next
Next
End Sub
Private Function GetValue(ByVal Name As String, ByVal obj As SWbemObject)
Dim pName
Dim pos
Dim tempstr
pName = Name & " = "
tempstr = obj.GetObjectText_
pos = InStr(tempstr, pName)
If pos <= 0 Then
GetValue = ""
Else
tempstr = Mid(tempstr, pos + Len(pName), Len(tempstr))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
tempstr = Trim(tempstr)
If obj.Properties_(Name).CIMType = 101 And Len(tempstr) > 14 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
End If
End Function
No comments:
Post a Comment