Sinisterly
[VB.Net] ShowWMIinfo Function - For all your WMI needs - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.Net] ShowWMIinfo Function - For all your WMI needs (/Thread-VB-Net-ShowWMIinfo-Function-For-all-your-WMI-needs)



[VB.Net] ShowWMIinfo Function - For all your WMI needs - Coder-san - 03-23-2011

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


RE: [VB.Net] ShowWMIinfo Function - For all your WMI needs - 1234hotmaster - 03-23-2011

Cool function man Biggrin all i knew from system.management till now was it was used for HWID Tongue

hey can't you contribute this function to Intellisense?


RE: [VB.Net] ShowWMIinfo Function - For all your WMI needs - Coder-san - 03-23-2011

That would require making it a dll, and for every use adding the dll as a reference + import.
A Function is easier. And remember no dependency of that dll. :p