List shares

Posted on 2005-04-20
Last Modified: 2008-11-11

If I have a server name, how do I get a list of shares on that server?
A code snippet would be appreciated.

Question by:bukko
    1 Comment
    LVL 53

    Accepted Solution

    You could try something like this, remember to have imports System.Management

    Private Sub EnumShares(ByVal Machine As String)
            'Local Shares
                Dim scope As String = ("\\" & Machine & "\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
                    MessageBox.Show("Description: " & Share("Description"))
                    MessageBox.Show("Name: " & Share("Name"))
                    MessageBox.Show("Path: " & Share("Path"))
            Catch ex As Exception
            End Try
    End Sub

    Although you'd probable only want those shares that have a type of 0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now