Results 1 to 6 of 6

Thread: Drive letters and identification

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    9

    Drive letters and identification

    I want to search a single drive specified by the user or all drives if the user de-selects the check box to limit to a single drive.

    However, I want the all drive search to limit to Hard Disks only (ignoring Floppies and CD's, zip drives etc). I have visualised a function which returns a string containing only the letters of the hard disks on the PC. I can then use this string to perform a search and update a database of specific files when it finds them.

    I am pretty sure that there is an API call to do this but I can't find any information about it and it's got me pulling my hair out.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Hopefully this will help get you started
    VB Code:
    1. Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
    2.  
    3. Private Sub GetDrives(CB As ComboBox, ByVal IsUsed As Boolean)
    4.            
    5.             Dim DriveLtr As Long
    6.             Dim StartPos As Integer
    7.  
    8.             If IsUsed = True Then  'if True is returned, then we want
    9.                StartPos = 0        'all drive letters in use
    10.             Else
    11.                StartPos = 4        'if False is returned, then we want
    12.             End If                 'to find an unused network drive, so
    13.                                    'skip A:, B:, C:, and D:
    14.             CB.Clear
    15.             For DriveLtr =StartPos To 25
    16.                 If CBool(GetLogicalDrives And (2 ^ DriveLtr)) = IsUsed Then
    17.                    CB.AddItem Chr$(Asc("A") + DriveLtr) & ":"
    18.                    'To check to see if a drive is already mapped, add this code
    19.                     'If Chr$(Asc("A") + DriveLtr) = "W" Then
    20.                      ' MsgBox "here it is"
    21.                    'End If
    22.                 End If
    23.             Next
    24. 'To Use:   GetDrives Combo1, True returns all drives letters currently in use
    25. '              GetDrives Combo1, False returns all available drive letters
    26. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    9
    @ Hack

    Thanks for that. I knew there was a way to do it but I didn't realise it was a Kernel32 call. There was my error, I was searching through the extensive list of API calls.... in the wrong libraries.

    And there was me thinking I had a brain DOH!

    But I have one additional Question with regard to the code. The help tells me that I have to use the DriveType Constant to identify Hard Disks only by using

    For DriveLtr =StartPos To 25
    If CBool(GetLogicalDrives And (2 ^ DriveLtr)) = IsUsed Then
    If DriveType = 2 Then
    "'anything that gets past here is a hard disk
    CB.AddItem Chr$(Asc("A") + DriveLtr) & ":"
    End If
    End If
    Next DriveLtr

    DriveType is located in the VB6.OLB Which has to be included... HOW?

    I have tried to view it in Notepad but it isn't even a txt file so I can't cut & paste. It won't add as a module and I can't even use "add File
    Last edited by Tryst; Mar 10th, 2002 at 06:10 PM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    An OLB is an object library which can be referenced. When you put together your setup and installation package, that library will be included.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    9
    Thanks again. I have included the reference now and I can only hope that it works now

    You would have thought MS would have made things a little easier.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    In the Microsoft World, this IS easy...

    Wait until you try to do something really complicated, like deal with unsigned integers (which is not supported in VB) or pointers (which is not supported in VB, but you can kinda, sorta, fake)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width