VB.NET - Listing mapped drives on a remote PC

I had written some code in VB.NET/Visual Studio 2012 but since then I lost all data on the hard drive and consequently lost the source code.
I have used .NET Reflector to get back most of it but I am puzzled by some entries which don't make any sense to me as I can't remember the code I used and it has changed it slightly:
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        Me.ListView1.Items.Clear()
        Me.Cursor = Cursors.WaitCursor
        Application.DoEvents()
        Main.WMICall(Main.txtHostName.Text)
        If Main.WMICall(Main.txtHostName.Text) Then
            Dim scope As New ManagementScope(("\\" & Main.txtHostName.Text & "\root\cimv2"))
            scope.Connect()
            Try
                Dim enumerator As ManagementObject
                Dim query As New ObjectQuery("Select * from Win32_MappedLogicalDisk")
                Dim objects As ManagementObjectCollection = New ManagementObjectSearcher(scope, query).Get
                Try
                    enumerator = objects.GetEnumerator
                    Do While enumerator.MoveNext
                        Dim current As ManagementObject = DirectCast(enumerator.Current, ManagementObject)
                        Dim items As String() = New String(3 - 1) {}
                        items(0) = ToString(current.Item("Name"))
                        items(1) = ToString(current.Item("ProviderName"))
                        Dim item As New ListViewItem(items)
                        Me.ListView1.Items.Add(item)
                    Loop
                Finally
                    If (Not enumerator Is Nothing) Then
                        enumerator.Dispose()
                    End If
                End Try
            Catch ex As Exception

            End Try
        End If
        Me.Cursor = Cursors.Default

    End Sub

Open in new window

It's this part that isn't recognised:
enumerator = objects.GetEnumerator
                    Do While enumerator.MoveNext
                        Dim current As ManagementObject = DirectCast(enumerator.Current, ManagementObject)

I have no idea what was there originally. Any help?
LVL 2
fruitloopyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi fruitloopy;

The original code may be more closer to the code snippet below.

Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
    Me.ListView1.Items.Clear()
    Me.Cursor = Cursors.WaitCursor
    Application.DoEvents()
    Main.WMICall(Main.txtHostName.Text)
    If Main.WMICall(Main.txtHostName.Text) Then
        Dim scope As New ManagementScope(("\\" & Main.txtHostName.Text & "\root\cimv2"))
        scope.Connect()
        Dim query As New ObjectQuery("Select * from Win32_MappedLogicalDisk")
        Dim objects As ManagementObjectCollection = New ManagementObjectSearcher(scope, query).Get
        
        For Each mObject As ManagementObject In objects
            Dim items As String() = New String(2) {}
            items(0) = mObject.Item("Name")
            items(1) = mObject.Item("ProviderName")
            Dim item As New ListViewItem(items)
            Me.ListView1.Items.Add(item)
        Loop
    End If
    Me.Cursor = Cursors.Default                               
End Sub 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fruitloopyAuthor Commented:
Close enough and it certainly gave me the will to carry on!
It's this code that got the job done:
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        ListView1.Items.Clear()
        Cursor = Cursors.WaitCursor
        Application.DoEvents()
        Main.WMICall(Main.txtHostName.Text)
        
        Try
            If Main.WMICall(Main.txtHostName.Text) Then
                Dim scope As New ManagementScope(("\\" & Main.txtHostName.Text & "\root\cimv2"))
                scope.Connect()
                Dim query As New ObjectQuery("Select * from Win32_MappedLogicalDisk")
                Dim objects As ManagementObjectCollection = New ManagementObjectSearcher(scope, query).Get
                Dim lvi As New ListViewItem
                Dim nX As Integer

                For Each mObject As ManagementObject In objects
                    nX += 1
                    lvi = ListView1.Items.Add(mObject("Name"))
                    lvi.SubItems.Add(mObject("ProviderName"))
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Me.Cursor = Cursors.Default

    End Sub

Open in new window

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.