Working with network drives

cdev19

New Member
Joined
Apr 12, 2009
Messages
8
Hi all,

Is there a way to extract the current network drive (including server) and Dim as a string?

Reason being all users are not necessarily on the same server and I want to Dim the full network path (including server) as a string if possible, as the full path is required for other pieces of code.
 
here is some code I use to create a batch file on a users desktop with all of the drive mappings, that aside you will be able to see the code for the drive and root bit, devicetype=3 is a network share

Private Sub MapMyDrives_Click()
'****
' Function to create a batch file to write the users current network drives to.
' this can be used by the user to create the file on their desktop so when they
' login using VPN the drives can be mapped in a faster way than a full login
'
' Author Jim Ward
' Creation 10th April 2008
'
'****

'****
' Declare what we need, general
'****

Dim fs, d, dc, l, n, s

'****
' Declare what we need to get the Desktop location
'****

Dim oWSS As Object
Const szlocation As String = "Desktop"
Dim szDesktopPath As String

'****
' get the desktop location
'****

Set oWSS = CreateObject("WScript.Shell")
szDesktopPath = oWSS.SpecialFolders(szlocation)

'****
' get the list of drives
'****

Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.Drives
s = ""

'****
' Process each one, ignoring local drives
' For each network drive (type=3) write a line to a BAT file
'****

Open szDesktopPath & "\MapMyDrives.BAT" For Output As #1

For Each d In dc
If d.DriveType = 3 Then
l = UCase(d.DriveLetter)
n = UCase(d.ShareName)
' s = s & "NET USE " & l & ": " & n & vbCrLf
Print #1, "NET USE " & l & ": " & n
ListBox1.AddItem "NET USE " & l & ": " & n
End If
Next
Close #1
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top