Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » API » Hard disk size


Hard disk sizeExpand / Collapse
Author
Message
Posted 6/9/2009 5:05:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/10/2009 8:57:40 AM
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..
Post #27768
Posted 6/10/2009 4:28:50 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: Today @ 12:42:47 AM
Posts: 125, Visits: 536
Have you tried GetFileInformationByHandle?

 

Good Luck

 

Post #27773
Posted 6/10/2009 7:26:16 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 8:17:02 AM
Posts: 1,751, Visits: 4,355
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.

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

http://www.martin2k.co.uk/forums/index.php?act=idx

I've been programming with VB for 14 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
 
Post #27775
Posted 6/10/2009 8:19:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/10/2009 8:57:40 AM
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
Post #27776
Posted 6/10/2009 4:36:10 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 8:17:02 AM
Posts: 1,751, Visits: 4,355
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.

Keith

http://www.martin2k.co.uk/forums/index.php?act=idx

I've been programming with VB for 14 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
 
Post #27779
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Brian, Peter

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 4:59am