Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Enumerate Shares on a Server - VB.NET

Posted on 2010-08-20
5
Medium Priority
?
1,456 Views
Last Modified: 2012-05-10
I would like to be able to enumerate the [disk] shares for a given server name.  I have seen some tips and sample code "out there" but it seems to be all old and decrepit.

Regards,

John



0
Comment
Question by:JXCovert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:SylvainDrapeau
ID: 33489707
Hello !

I've done it once using VB.NET and WMI. I can post the code if you're interested.

Syldra
0
 

Author Comment

by:JXCovert
ID: 33490126
I would be VERY intrigued to see your code, Sylvain.
0
 
LVL 8

Accepted Solution

by:
SylvainDrapeau earned 2000 total points
ID: 33490312
Hello !

I extracted the code from a large source so it's not the cleanest you've seen but it's clear enough I guess.

The code was made to query the local computer only but you can replace "\\.\root\cimv2" on the first line by "\\SERVER\root\cimv2" to query a remote server.

Call the function QueryShare to get an arraylist containing every share in the form "Share name (share path)". If you want only disk shares (and not path shares), add a filter around the "'Adds to result" command.

Syldra
Dim mScope As New ManagementScope("\\.\root\cimv2")
    Dim Searcher As ManagementObjectSearcher
    Dim Items As ManagementObjectCollection
   
    'Connect to WMI, exits if error
        Try
            mScope.Connect()
        Catch ex As Exception
            OutputWMIError(ex.Message)
            Exit Sub
        End Try
   
   Function QueryShare() As ArrayList
        Dim Result As New ArrayList
 
        'Lists all local shares
        Searcher = New ManagementObjectSearcher("SELECT Name, Path, Type FROM Win32_Share Where Type='0'")
        Searcher.Scope = mScope

        Try
            Items = Searcher.Get
            For Each moComputer As ManagementObject In Items
                'Adds to results
                Result.Add(moComputer("Name") & " (" & moComputer("Path") & ")")
            Next
        Catch ex As Exception
            Result.Add("Error : " & ex.Message)
        End Try
        Return Result
    End Function

Open in new window

0
 

Author Closing Comment

by:JXCovert
ID: 33614795
This worked perfectly for Window Server shares, but not for NAS shares.
0
 

Author Comment

by:JXCovert
ID: 33614796
Thanks, Sylvain,

John

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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