Home All Groups Group Topic Archive Search About
Author
4 Jun 2009 4:29 PM
Lorin
Is there an API that returns what FileSystemObject fso.Drives returns?

I need to get the
    .DriveType
    .IsReady
    .ShareName

Or what are the APIs for each?

The code I am replacing is as follows (snippet):

    Set drvDrives = fso.Drives
    For Each drvDrive In drvDrives
        sSuffix = " < DRIVE NOT READY >"
        sDrvLtr = drvDrive.DriveLetter    ' for reference
        Select Case drvDrive.DriveLetter
        Case "A", "B" ' floppy
            If bFloppyInclude Then
                bDrvReady = drvDrive.IsReady ' slow
            Else
                bDrvReady = False
                sSuffix = " < Not Checked > "
            End If

        Case Else
            bDrvReady = drvDrive.IsReady

        End Select

        If bDrvReady Then
            Select Case drvDrive.DriveType
            Case 1      ' removable  SUB + Floppy  ...
                ' skip
                sVolName = drvDrive.VolumeName
                'sVolName = vbNullString

            Case 3
                sVolName = drvDrive.ShareName

            Case Else           ' 2
                sVolName = drvDrive.VolumeName

            End Select

Author
4 Jun 2009 5:02 PM
MikeD
Show quote Hide quote
"Lorin" <lor***@hotmail.com> wrote in message news:0012948E-26D1-49A8-BBB6-E75CDFF83D68@microsoft.com...
> Is there an API that returns what FileSystemObject fso.Drives returns?
>
> I need to get the
>    .DriveType
>    .IsReady
>    .ShareName
>
> Or what are the APIs for each?
>
> The code I am replacing is as follows (snippet):
>
>    Set drvDrives = fso.Drives
>    For Each drvDrive In drvDrives
>        sSuffix = " < DRIVE NOT READY >"
>        sDrvLtr = drvDrive.DriveLetter    ' for reference
>        Select Case drvDrive.DriveLetter
>        Case "A", "B" ' floppy
>            If bFloppyInclude Then
>                bDrvReady = drvDrive.IsReady ' slow
>            Else
>                bDrvReady = False
>                sSuffix = " < Not Checked > "
>            End If
>
>        Case Else
>            bDrvReady = drvDrive.IsReady
>
>        End Select
>
>        If bDrvReady Then
>            Select Case drvDrive.DriveType
>            Case 1      ' removable  SUB + Floppy  ...
>                ' skip
>                sVolName = drvDrive.VolumeName
>                'sVolName = vbNullString
>
>            Case 3
>                sVolName = drvDrive.ShareName
>
>            Case Else           ' 2
>                sVolName = drvDrive.VolumeName
>
>            End Select


The Win32API function GetLogicalDriveStrings will provide you a single string of all the drive letters (you will need to parse this
string).  GetDriveType will tell you the drive type. I don't know how you'd get the share name, but possibly SHGetFileInfo or
FindFirstFile. The volume label you can get using VB's Dir$() function.

A search of the newsgroups at http://groups.google.com/advanced_search on those function names should provide you with tons of
example code.


--
Mike
Author
4 Jun 2009 5:49 PM
Rick Rothstein
Here is function I created years (and years) ago which will tell you (it
returns True or False) if a CD or DVD is in your the optical drive whose
letter you pass into it or not...

Private Declare Function GetVolumeInformation _
                Lib "kernel32.dll" _
                Alias "GetVolumeInformationA" _
               (ByVal lpRootPathName As String, _
                ByVal lpVolumeNameBuffer As String, _
                ByVal nVolumeNameSize As Integer, _
                lpVolumeSerialNumber As Long, _
                lpMaximumComponentLength As Long, _
                lpFileSystemFlags As Long, _
                ByVal lpFileSystemNameBuffer As String, _
                ByVal nFileSystemNameSize As Long) As Long

Function IsCD(DriveLetter As String) As Boolean
  Dim VolName As String
  Dim FSys As String
  Dim erg As Long
  Dim VolNumber As Long
  Dim MCM As Long
  Dim FSF As Long
  If Right$(DriveLetter, 1) <> ":" Then
    DriveLetter = DriveLetter & ":"
  End If
  If Len(DriveLetter) = 2 Then
    VolName = Space$(127)
    FSys = Space$(127)
    If GetVolumeInformation(DriveLetter, VolName, 127&, _
       VolNumber, MCM, FSF, FSys, 127&) Then IsCD = True
  End If
End Function

--
Rick (MVP - Excel)


Show quoteHide quote
"Lorin" <lor***@hotmail.com> wrote in message
news:0012948E-26D1-49A8-BBB6-E75CDFF83D68@microsoft.com...
> Is there an API that returns what FileSystemObject fso.Drives returns?
>
> I need to get the
>    .DriveType
>    .IsReady
>    .ShareName
>
> Or what are the APIs for each?
>
> The code I am replacing is as follows (snippet):
>
>    Set drvDrives = fso.Drives
>    For Each drvDrive In drvDrives
>        sSuffix = " < DRIVE NOT READY >"
>        sDrvLtr = drvDrive.DriveLetter    ' for reference
>        Select Case drvDrive.DriveLetter
>        Case "A", "B" ' floppy
>            If bFloppyInclude Then
>                bDrvReady = drvDrive.IsReady ' slow
>            Else
>                bDrvReady = False
>                sSuffix = " < Not Checked > "
>            End If
>
>        Case Else
>            bDrvReady = drvDrive.IsReady
>
>        End Select
>
>        If bDrvReady Then
>            Select Case drvDrive.DriveType
>            Case 1      ' removable  SUB + Floppy  ...
>                ' skip
>                sVolName = drvDrive.VolumeName
>                'sVolName = vbNullString
>
>            Case 3
>                sVolName = drvDrive.ShareName
>
>            Case Else           ' 2
>                sVolName = drvDrive.VolumeName
>
>            End Select
>
>
>