Getting the name of a mapped share, using vbs

Posted on 2011-10-25
Last Modified: 2012-05-12
Is there a way I can use VBS to list the network mappings for the current user and the names of the shares?

For example, say that a network user can see network drives J: , X: and M: when they login.

I would like to have a script that when clicked on returns something similar to:

\\SERVER001\SALES\ as J:
\\SERVER002\ENG\ as X:
\\ERDMAIN\JSmith$\ as M:


Question by:snyperj
    LVL 12

    Expert Comment

    Try the following...
    const bytesToGb = 1073741824
    strComputer = "." ' Local Computer
    set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    set colDrives = objWMI.ExecQuery("select * from Win32_MappedLogicalDisk")
    for each objDrive in colDrives
    	WScript.Echo "Device ID: " & objDrive.DeviceID & vbcrlf & _
       		     "Volume Name: " & objDrive.VolumeName & vbcrlf & _
    		     "Session ID: " & objDrive.SessionID & vbcrlf & _
    		     "Size: " & round(objDrive.Size / bytesToGb,1) & " Gb"

    Open in new window

    LVL 6

    Accepted Solution

    I use next code:

    Set objNetwork = CreateObject("WScript.Network")
    Set colDrives = objNetwork.EnumNetworkDrives
    TempDepartmentFolder = ""
    If colDrives.Count > 0 Then 
      For intDrive = 0 To (colDrives.Count -1) Step 2
        intNetLetter = IntNetLetter +1
        WScript.Echo colDrives.Item(intDrive)&" "&colDrives.Item(intDrive +1)
    End if

    Open in new window

    LVL 11

    Expert Comment

    strComputer = "." ' Local Computer
    SET objWMI = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
    SET colDrives = objWMI.ExecQuery("select * from Win32_MappedLogicalDisk")
    FOR EACH objDrive in colDrives
    	WScript.Echo objDrive.ProviderName & " as " & objDrive.Name

    Open in new window

    LVL 51

    Expert Comment

    by:Bill Prew
    I know you asked for a VBS script, but just in case you aren't aware, there is a simple command that you can do in a BAT file or a command line to show this info as well, give it a try.  If you are integrating into a larger VBS effort etc then feel free to ignore this, but figured no harm in passing it along.


    Open in new window


    Author Closing Comment

    Thanks to all who answered

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now