Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Hard disk size


Hard disk size

Author
Message
Shreeti_Tula
Shreeti_Tula
Forum God
Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)

Group: Forum Members
Posts: 7, Visits: 18
I know there are lots of question being asked about this but i still have not found the solution. Can anybody help to find the total size of hard disk not the logical size. GetDiskFreeSpaceEx only helps to get the logical size. Please help..
vb5prgrmr
vb5prgrmr
Forum God
Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)Forum God (39K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Have you tried GetFileInformationByHandle?

 

Good Luck

 

Keithuk
Keithuk
Forum God
Forum God (291K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
Shreeti_Tula (6/9/2009)
I know there are lots of question being asked about this but i still have not found the solution. Can anybody help to find the total size of hard disk not the logical size. GetDiskFreeSpaceEx only helps to get the logical size. Please help..

Well I've always used GetDiskFreeSpaceEx API to get the total drive size and the free space, its always worked for me. Wink

Option Explicit

Dim Status As Long
Dim TotalBytes As Currency
Dim FreeBytes As Currency
Dim BytesAvailableToCaller As Currency
Dim DiskSize As String
Dim DiskSpace As String

Private Declare Function cc Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As CurrencyAs Long

Private Sub Command1_Click

Status = GetDiskFreeSpaceEx("C:\", BytesAvailableToCaller, TotalBytes, FreeBytes)
If Status = 0 Then
    DiskSize = "Unknown"
    DiskSpace = "Unknown"
Else
    DiskSize = Format(TotalBytes * 10000, "#,##0") & " Bytes"
    DiskSpace = Format(FreeBytes * 10000, "#,##0") & " Bytes"
End If

MsgBox "Disk Size: " & DiskSize
MsgBox "Free Space: " & DiskSpace

End Sub


Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Shreeti_Tula
Shreeti_Tula
Forum God
Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)Forum God (3K reputation)

Group: Forum Members
Posts: 7, Visits: 18
thanks. I may be wrong but as far as i know this api gives only the logical drive size. As for the example you have shown it gives the total size of c drive only. But i need the total size of harddisk i.e that may contain c,d,e... logical drive
Keithuk
Keithuk
Forum God
Forum God (291K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
Shreeti_Tula (6/10/2009)
thanks. I may be wrong but as far as i know this api gives only the logical drive size. As for the example you have shown it gives the total size of c drive only. But i need the total size of harddisk i.e that may contain c,d,e... logical drive

Well to me the logical size is the actual size. I have a 40GB drive and it shows 40,006,156,288 Bytes and I have 28,899,593,344 Bytes free.

I only showed an example using C: drive but you could cycle through all the available fixed drives to find there size. Wink

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

sunitasamal
sunitasamal
Forum God
Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)Forum God (459 reputation)

Group: Forum Members
Posts: 1, Visits: 4
You can refer to the following link :

http://vbnet.mvps.org/index.html?code/disk/deviodriveinfo.htm 

If you find difficulty in getting the code I can explain.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search