• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

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!

0
snyperj
Asked:
snyperj
1 Solution
 
prashanthdCommented:
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

0
 
morpheiosCommented:
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)
  Next
End if

wscript.quit

Open in new window

0
 
X_layerCommented:
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

0
 
Bill PrewCommented:
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
0
 
snyperjAuthor Commented:
Thanks to all who answered
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now