Results 1 to 6 of 6

Thread: [RESOLVED] Check for Second Partition or Harddrive

  1. #1

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Resolved [RESOLVED] Check for Second Partition or Harddrive

    hey all
    does anyone know if its possible to check to see if there is a second Harddrive or partition on a system and to get the drive letter of it ?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Check for Second Partition or Harddrive

    This would list all available partitions, maybe that give you a start?

    Code:
    Option Explicit
    
    ' GetDriveType return values
    Private Const DRIVE_REMOVABLE = 2
    Private Const DRIVE_FIXED = 3
    Private Const DRIVE_REMOTE = 4
    Private Const DRIVE_CDROM = 5
    Private Const DRIVE_RAMDISK = 6
    
    Private Declare Function GetDriveType Lib "kernel32" Alias _
    "GetDriveTypeA" (ByVal nDrive As String) As Long
    
    
    Private Declare Function GetLogicalDriveStrings Lib _
    "kernel32" Alias "GetLogicalDriveStringsA" _
    (ByVal nBufferLength As Long, ByVal _
    lpBuffer As String) As Long
    
    Sub Form_Load()
            
        Dim sDrive As String
        Dim NumDrvs As Long
        Dim i As Integer
        
        NumDrvs = GetLogicalDriveStrings(0&, sDrive)
        sDrive = String(NumDrvs - 1, " ")
        NumDrvs = GetLogicalDriveStrings(NumDrvs, sDrive)
        
        For i = 1 To NumDrvs Step 4
            If GetDriveType(Mid(sDrive, i, 2)) = DRIVE_FIXED Then
                List1.AddItem Mid(sDrive, i, 2)
                End If
        Next i
        
    End Sub

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Check for Second Partition or Harddrive

    If you ask the OS it will give you all the drive letters of all drives???????

  4. #4
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check for Second Partition or Harddrive

    I assembled a class devoted to drive functions that may be of interest, attached at the end of this post. It can be used separately, or as part of a larger library, which can found linked in my signature. Enumerating hard drives is one of the many features you might find useful.

    Here's an example of how you can use it to enumerate all the hard drives:
    vb Code:
    1. Public Sub Sample()
    2.     Dim drv As clsDrive
    3.     Dim strDrives() As String
    4.     Dim i As Long
    5.    
    6.     Set drv = New clsDrive
    7.     For i = 1 To drv.EnumerateFixed(strDrives)
    8.         Debug.Print strDrives(i)
    9.     Next
    10.     Erase strDrives
    11.     Set drv = Nothing
    12. End Sub
    Here's the Read.Me for clsDrive.cls:

    clsDrive

    CloseDoor()
    drv.CloseDoor [Drive]
    Closes the CD or DVD door only if the drive is of the appropriate type. Trying close a hard drive or floppy disk is safely ignored. [Drive] should be a string in the format "D:"; if you omit the Drive parameter the default CD is closed.

    Eject()
    drv.Eject [Drive]
    Ejects the CD or DVD only if the drive is of the appropriate type. Trying to eject a hard drive or floppy disk is safely ignored. [Drive] should be a string in the format "D:"; if you omit the Drive parameter the default CD is ejected.

    FormatSize()
    strSize = drv.FormatSize(curSize)
    Returns a formatted string description of the specified (currency) size. This string is formatted the same way as displayed in the Explorer status bar. (eg: 37 bytes, 63.2 KB, 123 KB, 64.2 MB, 153 MB, 4.22 GB)

    GetDriveSpace()
    drv.GetDriveSpace "C:", curTotal, curFree, curUsed
    Retrieves all three drive space statistics (Total, Free, Used) in a single operation. Send three currency variables to be filled in by reference. Use the FormatSize() function to convert these values for display.

    GetFreeSpace()
    curFree = drv.GetFreeSpace("C:")
    Returns the free space on the specified drive. Use the FormatSize() function to convert the value for display.

    GetTotalSpace()
    curFree = drv.GetTotalSpace("C:")
    Returns the total space on the specified drive. Use the FormatSize() function to convert the value for display.

    GetUsedSpace()
    curFree = drv.GetUsedSpace("C:")
    Returns the used space on the specified drive. Use the FormatSize() function to convert the value for display.

    GetFileSystem()
    strFileSystem = drv.GetFileSystem("C:")
    Returns the file system (eg: "NTFS") of the specified drive.

    GetName()
    strLabel = drv.GetName("C:")
    Returns the volume label.

    GetSerialNumber()
    lngSerial = drv.GetSerialNumber("C:")
    Returns the serial number of the specified drive. (Some drives return 0 due to not being branded by the manufacturer.)

    GetType()
    enType = drv.GetType("C:")
    Returns the enumerated drive type of the specified drive.

    SetName()
    drv.SetName "C:", "MyVolumeLabel"
    Sets the volume label.

    DRIVE ENUMERATIONS

    The four types of drive enumerations (All, Hard Drives, CD/DVDs, Floppies) all work the same way. Send a dynamic string array to be populated as a one-based array, and it will return the number of drives found. The strings in the array will be in the format "A:", "C:", etc...

    lngDrives = drv.EnumerateAll(StringArray)
    lngDrives = drv.EnumerateCDs(StringArray)
    lngDrives = drv.EnumerateFixed(StringArray)
    lngDrives = drv.EnumerateFloppies(StringArray)
    Attached Files Attached Files

  5. #5

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: Check for Second Partition or Harddrive

    thanks for the suggestions guys
    @Edgemeal ill give it a try
    @Ellis Dee thanks alot for the class ill check it out it looks pretty good

  6. #6

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: [RESOLVED] Check for Second Partition or Harddrive

    playing around with Ellis Dee's class looks like it could do the trick thanks alot guys

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