remaining free space on HD
-
is there a way to check the remaining free space availabe on the Hard Disk and notify the user of that? I mean how can i display a popup msg to the user when the free remaining size reaches 90% for example?
Regards Ramy
-
is there a way to check the remaining free space availabe on the Hard Disk and notify the user of that? I mean how can i display a popup msg to the user when the free remaining size reaches 90% for example?
Regards Ramy
System.Management.ManegementObjectSeacher("Win32_OperatingSystem class")[^] -- modified at 4:37 Monday 30th April, 2007
-
is there a way to check the remaining free space availabe on the Hard Disk and notify the user of that? I mean how can i display a popup msg to the user when the free remaining size reaches 90% for example?
Regards Ramy
Try this. In this example you will need one button and 3 textboxes.Hope this helps Declareations
Inherits System.Windows.Forms.Form Private Declare Function GetDiskFreeSpaceEx _ Lib "kernel32" _ Alias "GetDiskFreeSpaceExA" _ (ByVal lpDirectoryName As String, _ ByRef lpFreeBytesAvailableToCaller As Long, _ ByRef lpTotalNumberOfBytes As Long, _ ByRef lpTotalNumberOfFreeBytes As Long) As Long Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = GetFreeSpace("C:\") TextBox2.Text = GetTotalSpace("C:\") GetPercentageFree() If TextBox3.Text < 36 Then MsgBox("You are running out of space") End If End Sub Public Function GetFreeSpace(ByVal Drive As String) As Long 'returns free space in MB, formatted to two decimal places 'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB") Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long Dim iAns As Long iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _ lBytesTotal, lFreeBytes) If ians > 0 Then Return BytesToMegabytes(lFreeBytes) Else Throw New Exception("Invalid or unreadable drive") End If End Function Public Function GetTotalSpace(ByVal Drive As String) As String 'returns total space in MB, formatted to two decimal places 'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB") Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long Dim iAns As Long iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _ lBytesTotal, lFreeBytes) If iAns > 0 Then Return BytesToMegabytes(lBytesTotal) Else Throw New Exception("Invalid or unreadable drive") End If End Function Private Function BytesToMegabytes(ByVal Bytes As Long) _ As Long Dim dblAns As Double dblAns = (Bytes / 1024) / 1024 BytesToMegabytes = Format(dblAns, "###,###,##0.00") End Function Public Function GetPercentageFree() Dim free As Integer Dim total As Integer Dim percent As Integer free = GetFreeSpace("C:\") total = GetTotalSpace("C:\") percent = (free / total) * 100 TextBox3.Text = percent End Function