Link to home
Start Free TrialLog in
Avatar of snyperj
snyperjFlag for United States of America

asked on

Getting the name of a mapped share, using vbs

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:

Thanks!

Avatar of prashanthd
prashanthd
Flag of India image

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"
next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of morpheios
morpheios
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of X_layer
Simple:
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
NEXT

Open in new window

Avatar of Bill Prew
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.

NET USE

Open in new window

~bp
Avatar of snyperj

ASKER

Thanks to all who answered