EnumNetworkDrives

  • Thread starter Thread starter fred
  • Start date Start date
F

fred

The following VB Script lists all of the mapped network drives. How can I
get the same information using VB.Net.

Thanks,
Fred


Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
Next
WScript.Echo
 
Its more or less the same except that you'll use the CreateObject function
provided in VB. However, you'll need to have option strict off for this one
(I'm not sure if you can reference wshom.ocx (Windows Script Host Object
Model) in a VB .NET project; you can give it a try so that you can have
option strict on):

dim o as Object = CreateObject("WScript.Network")
dim odrives as Object = o.EnumNetworkDrives
for i as integer = 0 to oDrives.Count - 1 Step 2
MessageBox.Show("Drive " & odrives.Item(i) & " = " &
odrives.Item(i+1))
next i


hope that helps..
Imran.
 
Thought you might like to know that in vb.net 2003 you can reference Widows
Script Host Object and your code does work to get the NetWork Drives.
 
Another way to look at the logical drives on a machine is to do something like the following:

Private Sub InterateThroughMyDrives()
Dim Drives() as String = System.Environment.GetLogicalDrives()
For Each Drive as String in Drives
msgbox(Drive)
Next
End Sub

Robert Schoen (Microsoft Visual Basic QA)
--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
--------------------
 
I don't believe this will give you the Shared Drives on the Network, just the
Network Mapped Drives. Is this correct?
 
I am slightly confused by your question... It will give you your logical drives on your local system only...including those that are mapped.
If you have a mapped drive typically that is to a shared network resource.

if you want to know the share name of your "mapped" drives you can do something with Windows Script Host Object Model. This will allow you to do:
Dim MyFileSystemObject As New IWshRuntimeLibrary.FileSystemObject
For Each Drive As IWshRuntimeLibrary.Drive In MyFileSystemObject.Drives
MsgBox(Drive.ShareName) ' to see share name
MsgBox(Drive.DriveLetter) ' to see local drive letters
Next

There is probably some other info you can get here as well...
Robert Schoen (Microsoft Visual Basic QA)
--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top