How To Enum Network File Shares


Private Sub btnEnumShares_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tnEnumShares.Click 
        'Local Shares 
        Try 
            Dim scope As String = ("\\ss-dotnetdev1\root\cimv2") 
            Dim SharesClass As ManagementClass = New ManagementClass(scope, "Win32_Share", Nothing) 
            Dim Shares As System.Management.ManagementObjectCollection = SharesClass.GetInstances() 
            Dim Share As System.Management.ManagementObject 

            For Each Share In Shares 
                MsgBox(Share("Description")) 
                MsgBox(Share("Name")) 
                MsgBox(Share("Path")) 
                'MsgBox(Share("Type")) 
            Next 
        Catch ex As Exception 
            MsgBox(ex.ToString) 
        End Try 

        'Network shares 
        Try 
            Dim scope As String = ("\\ss-dotnetdev1\root\cimv2") 
            Dim DrivesClass As ManagementClass = New ManagementClass(scope, "Win32_LogicalDisk", Nothing) 
            Dim Drives As System.Management.ManagementObjectCollection = DrivesClass.GetInstances() 
            Dim Drive As System.Management.ManagementObject 

            For Each Drive In Drives 
                If Convert.ToSingle(Drive("DriveType")) = 4 Then 
                    MsgBox(Drive("Name")) 
                    MsgBox(Drive("ProviderName")) 
                End If 
            Next 
        Catch ex As Exception 
            MsgBox(ex.ToString) 
        End Try 

    End Sub