Click here to Skip to main content
15,891,567 members
Articles / Programming Languages / Visual Basic

Retrieving Information From Windows Management Instrumentation

Rate me:
Please Sign up or sign in to vote.
4.93/5 (39 votes)
15 Jul 2010CDDL15 min read 85.5K   7.4K   62  
How to use WMI to get system information and present it to the user in an easy to understand format.
Option Strict On
Option Explicit On

Imports System.Environment


Public Class UserControlSpecialFolders

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        GetSpecialFolders()

    End Sub

    Dim folderList As New Dictionary(Of String, String)

    Private Sub GetSpecialFolders()

        Dim folderNames As String() = System.Enum.GetNames(GetType(Environment.SpecialFolder))

        For Each folder As String In folderNames
            Dim lvi As New ListViewItem

            ' Alternate each items' background colour.
            If lstSpecialFolders.Items.Count Mod 2 <> 0 Then
                lvi.BackColor = Color.White
            Else
                lvi.BackColor = Color.Ivory
            End If

            folderList.Add(folder, GetFolderPath(CType(System.Enum.Parse(GetType(SpecialFolder), CType(folder, String)), SpecialFolder)))

            lvi.Text = folder
            lvi.SubItems.Add(folderList.Item(folder))
            lstSpecialFolders.Items.Add(lvi)
        Next

    End Sub

    Public Sub CollectReportData()

        Dim newReport As TextReport = FormMain.TextReportFile

        For Each folderEntry As KeyValuePair(Of String, String) In folderList
            newReport.WriteItem(folderEntry.Key, folderEntry.Value)
        Next

        newReport.WriteSubtitle("")

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Other
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions