Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Display a list of all logical drives and include full paths for mapped drives

I am trying to write some VBA code to list all the drives on my
computer and if they are mapped show the full path they map to. I am
trying to do this to help work across many computers better. I am
trying to understand were some spreadsheet/macro users are getting some
data from.

Here is some code I got from the Microsoft Knowledge Base. It gives me
the list of logical dirve letters on my PC but no path for the mapped
drives.'

Thanks
Scott

Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Function GetDriveStrings() As String
' Wrapper for calling the GetLogicalDriveStrings API

Dim result As Long ' Result of our api calls
Dim strDrives As String ' String to pass to api call
Dim lenStrDrives As Long ' Length of the above string

' Call GetLogicalDriveStrings with a buffer size of zero to
' find out how large our stringbuffer needs to be
result = GetLogicalDriveStrings(0, strDrives)

strDrives = String(result, 0)
lenStrDrives = result

' Call again with our new buffer
result = GetLogicalDriveStrings(lenStrDrives, strDrives)

If result = 0 Then
' There was some error calling the API
' Pass back an empty string
' NOTE - TODO: Implement proper error handling here
GetDriveStrings = ""
Else
GetDriveStrings = strDrives
End If
End Function

Private Sub CommandButton1_Click()
Dim strDrives As String

' Find out what drives we have on this machine
strDrives = GetDriveStrings()

If strDrives = "" Then
' No drives were found
MsgBox "No Drives were found!", vbCritical
Else
' Walk through the string and list each drive
DisplayDriveTypes strDrives
End If
End Sub

Private Sub DisplayDriveTypes(drives As String)
' Walk through the logical drive string and display the drive
' letters. The logical drive string is a null seperated
' double null terminated string.

Dim pos As Long
Dim drive As String

ListBox1.Clear
pos = 1

Do While Not Mid$(drives, pos, 1) = Chr(0)
drive = Mid$(drives, pos, 3)
pos = pos + 4
ListBox1.AddItem UCase(drive)
Loop
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Display a list of all logical drives and include full paths for ma

http://support.microsoft.com/default...;en-us;Q192689
Q192689 - HOWTO: Get UNC Path From a Mapped Network Share's Drive Letter


http://support.microsoft.com/default...;en-us;Q291573
HOWTO: Use Visual Basic to List Active Logical Drives

http://support.microsoft.com/default...;en-us;Q189667
HOWTO: List the Drives in a System Using the FileSystemObject


http://support.microsoft.com/default...;en-us;Q256847
Q256847 - HOWTO: Use the WNetUseConnection API to Map a Drive in Visual Basic

--
Regards,
Tom Ogilvy


" wrote:

I am trying to write some VBA code to list all the drives on my
computer and if they are mapped show the full path they map to. I am
trying to do this to help work across many computers better. I am
trying to understand were some spreadsheet/macro users are getting some
data from.

Here is some code I got from the Microsoft Knowledge Base. It gives me
the list of logical dirve letters on my PC but no path for the mapped
drives.'

Thanks
Scott

Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Function GetDriveStrings() As String
' Wrapper for calling the GetLogicalDriveStrings API

Dim result As Long ' Result of our api calls
Dim strDrives As String ' String to pass to api call
Dim lenStrDrives As Long ' Length of the above string

' Call GetLogicalDriveStrings with a buffer size of zero to
' find out how large our stringbuffer needs to be
result = GetLogicalDriveStrings(0, strDrives)

strDrives = String(result, 0)
lenStrDrives = result

' Call again with our new buffer
result = GetLogicalDriveStrings(lenStrDrives, strDrives)

If result = 0 Then
' There was some error calling the API
' Pass back an empty string
' NOTE - TODO: Implement proper error handling here
GetDriveStrings = ""
Else
GetDriveStrings = strDrives
End If
End Function

Private Sub CommandButton1_Click()
Dim strDrives As String

' Find out what drives we have on this machine
strDrives = GetDriveStrings()

If strDrives = "" Then
' No drives were found
MsgBox "No Drives were found!", vbCritical
Else
' Walk through the string and list each drive
DisplayDriveTypes strDrives
End If
End Sub

Private Sub DisplayDriveTypes(drives As String)
' Walk through the logical drive string and display the drive
' letters. The logical drive string is a null seperated
' double null terminated string.

Dim pos As Long
Dim drive As String

ListBox1.Clear
pos = 1

Do While Not Mid$(drives, pos, 1) = Chr(0)
drive = Mid$(drives, pos, 3)
pos = pos + 4
ListBox1.AddItem UCase(drive)
Loop
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Display a list of all logical drives and include full paths for ma

The first link you sent worked perfectly. I had searched the MSKB but
did not understand the titles enough to look into some of them further.

Thanks
Scott

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapped vs Network drives Greg Excel Worksheet Functions 2 January 12th 10 07:16 PM
Modified date issues when saving to mapped drives using Excel 2007 Liverpool Excel Discussion (Misc queries) 0 June 4th 08 06:08 PM
Linked cells and Mapped Network Drives James McDowell Excel Worksheet Functions 3 May 10th 06 06:42 PM
2 DFS Mapped drives confuses active links in Excel Steve Jackson Links and Linking in Excel 1 July 29th 05 08:10 AM
saving files with mapped drives Derek Excel Discussion (Misc queries) 0 May 9th 05 07:49 PM


All times are GMT +1. The time now is 10:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"