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 ?
Printable View
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 ?
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
If you ask the OS it will give you all the drive letters of all drives???????
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:Here's the Read.Me for clsDrive.cls:vb Code:
Public Sub Sample() Dim drv As clsDrive Dim strDrives() As String Dim i As Long Set drv = New clsDrive For i = 1 To drv.EnumerateFixed(strDrives) Debug.Print strDrives(i) Next Erase strDrives Set drv = Nothing End Sub
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)
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 :)
playing around with Ellis Dee's class looks like it could do the trick thanks alot guys