PC Review


Reply
Thread Tools Rate Thread

Display a list of all logical drives and include full paths for mapped drives

 
 
brotherescott@yahoo.com
Guest
Posts: n/a
 
      10th Aug 2006
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      10th Aug 2006
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


"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
brotherescott@yahoo.com
Guest
Posts: n/a
 
      11th Aug 2006
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding paths for mapped drives havenlad Windows XP Basics 3 5th Nov 2008 04:33 PM
Mapping drives automatically. Remembering passwords for mapped drives. Sameer Microsoft Windows 2000 Networking 1 18th Jun 2007 12:14 PM
Drive Letter clash (mapped network drives vs physical drives) =?Utf-8?B?T2xpdmVyIFdoaXRlbWFu?= Windows XP General 4 4th Aug 2005 09:59 AM
Enumerate all the drives including Mapped network drives on a serv =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?= Microsoft ASP .NET 2 26th Feb 2005 03:13 PM
Disk Management does not display logical drives CWDog Microsoft Windows 2000 Advanced Server 0 4th Dec 2003 11:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:37 PM.