Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. remaining free space on HD

remaining free space on HD

Scheduled Pinned Locked Moved Visual Basic
questiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    charchabil03
    wrote on last edited by
    #1

    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

    S J 2 Replies Last reply
    0
    • C charchabil03

      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

      S Offline
      S Offline
      Sonia Gupta
      wrote on last edited by
      #2

      System.Management.ManegementObjectSeacher("Win32_OperatingSystem class")[^] -- modified at 4:37 Monday 30th April, 2007

      1 Reply Last reply
      0
      • C charchabil03

        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

        J Offline
        J Offline
        johnjsm
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups