Login Register


[VB.Net] ShowWMIinfo Function - For all your WMI needs filter_list
Author
Message
[VB.Net] ShowWMIinfo Function - For all your WMI needs #1
Hello VB Programmers. Smile
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). Smile
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 Sub


Usage:
Code:
ShowWMIinfo(ListView1, "win32_processor")

Have a good day. Smile
[Image: rytwG00.png]
Redcat Revolution!

Reply





Messages In This Thread
[VB.Net] ShowWMIinfo Function - For all your WMI needs - by Coder-san - 03-23-2011, 04:01 PM



Users browsing this thread: 1 Guest(s)