[VB.Net] ShowWMIinfo Function - For all your WMI needs 03-23-2011, 04:01 PM
#1
Hello VB Programmers. 
What I'm sharing with you today is a function from my vSystemInfo program.
You probably have heard of WMI, it gets pretty messy at times.
I present to you a simple Function capable of nicely showing all Properties of a WMI class by a single line of code (Function Call).
Currently it is not capable of executing queries and fetching results, I'm too lazy to parse all that.
First Add System.Management as a Reference, then Import the same.
For using this function you need to have a ListView control on your Form in Details View with at least 2 Coloumns.
You can get names of [link=http://msdn.microsoft.com/en-us/library/aa392727%28v=vs.85%29.aspx]WMI classes here.[/link]
Usage:
Have a good day.

What I'm sharing with you today is a function from my vSystemInfo program.
You probably have heard of WMI, it gets pretty messy at times.
I present to you a simple Function capable of nicely showing all Properties of a WMI class by a single line of code (Function Call).

Currently it is not capable of executing queries and fetching results, I'm too lazy to parse all that.
First Add System.Management as a Reference, then Import the same.
For using this function you need to have a ListView control on your Form in Details View with at least 2 Coloumns.
You can get names of [link=http://msdn.microsoft.com/en-us/library/aa392727%28v=vs.85%29.aspx]WMI classes here.[/link]
Spoiler: Source
Code:
Public Sub ShowWMIinfo(ByVal ListInfo As ListView, ByVal WMIclass As String)
Try
'Return Nothing
Dim objWMIService As New ManagementClass(WMIclass)
Dim objWMI As System.Management.ManagementObjectCollection = objWMIService.GetInstances()
Dim WMIstats As String() = Nothing
For Each objItem As Management.ManagementObject In objWMI
Try
WMIstats = objItem.GetText(TextFormat.Mof).Substring(15 + WMIclass.Length, objItem.GetText(TextFormat.Mof).Length - (15 + WMIclass.Length)).Replace("""", "").Split(CChar(";"))
Catch ex As Exception
End Try
Next
'ListInfo.BeginUpdate()
For intA As Integer = 0 To UBound(WMIstats)
With ListInfo.Items
.Add(WMIstats(intA).Substring(0, WMIstats(intA).LastIndexOf("=")), 1)
.Item(intA).SubItems.Add(WMIstats(intA).Substring(WMIstats(intA).LastIndexOf("=") + 2))
End With
Next
'ListInfo.EndUpdate()
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End SubUsage:
Code:
ShowWMIinfo(ListView1, "win32_processor")Have a good day.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!

![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
all i knew from system.management till now was it was used for HWID 