Network Disk Space

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    Network Disk Space

    Hi!

    I downloaded some software that checks hard disk usage for all the pc's on our network. My question is how?? Is there some sort of dos command or api call or something? I want to create a Visual Basic ap to do the same thing so I can tailor it to give warnings when some disks reach certain levels.

    Any info regarding this would be most helpful!

    Thanks


    Andy
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Yes i created a small app to do this for my network drives, although i did it in vb 2005.

    it used the follwing api
    [code=vbnet]
    Private Declare Function GetDiskFreeSpac eEx Lib "kernel32" Alias "GetDiskFreeSpa ceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvai lableToCaller As Long, ByRef lpTotalNumberOf Bytes As Long, ByRef lpTotalNumberOf FreeBytes As Long) As Long
    [/code]

    if you want my full vb2005 code then post back and i'll add it here.

    James

    Comment

    • theS70RM
      New Member
      • Jul 2007
      • 107

      #3
      oh nice one,

      yea i dunno if you want to post the full code, or an example of how to impliment that api call for a given network drive would be nice.

      Cheers!

      Andy

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Ok this is written in vb 2005...

        [code=vb]
        Private Declare Function GetDiskFreeSpac eEx Lib "kernel32" Alias "GetDiskFreeSpa ceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvai lableToCaller As Long, ByRef lpTotalNumberOf Bytes As Long, ByRef lpTotalNumberOf FreeBytes As Long) As Long
        Public Function GetFreeSpace(By Val 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, lFreeBytesAvail able As Long
        Dim iAns As Long
        iAns = GetDiskFreeSpac eEx(Drive, lFreeBytesAvail able, _
        lBytesTotal, lFreeBytes)
        If iAns > 0 Then
        Return BytesToMegabyte s(lFreeBytes)
        Else
        Throw New Exception("Inva lid or unreadable drive")
        End If
        End Function
        Public Function GetTotalSpace(B yVal 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, lFreeBytesAvail able As Long
        Dim iAns As Long
        iAns = GetDiskFreeSpac eEx(Drive, lFreeBytesAvail able, _
        lBytesTotal, lFreeBytes)
        If iAns > 0 Then
        Return BytesToMegabyte s(lBytesTotal)
        Else
        Throw New Exception("Inva lid or unreadable drive")
        End If
        End Function
        Private Function BytesToMegabyte s(ByVal Bytes As Long) As Long
        Dim dblAns As Double
        dblAns = (Bytes / 1024) / 1024
        BytesToMegabyte s = Format(dblAns, "###,###,##0.00 ")
        End Function
        [/code]

        I call it like this:
        [code=vb]
        Dim jkp As Double = GetFreeSpace("\ \123.45.678.90\ C$") / 1024
        Label5.Text = "DD2: " & Format(jkp, "###,###,##0.00 ") & " GB"
        [/code]

        James

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          I don't think it's entirely clear so far what you want. Is this something you want to run on a server to monitor all the PC's connected to the network?

          If you're just after information about the network drives connected to your PC, here's a much simpler example...
          [CODE=vb]Private Sub Form_Click()
          Dim fso As New FileSystemObjec t
          Dim drv As Drive
          For Each drv In fso.Drives
          With drv
          If .DriveType = Remote Then
          Me.Print .DriveLetter, .DriveType, .AvailableSpace
          End If
          End With
          Next
          Set drv = Nothing
          Set fso = Nothing
          End Sub[/CODE]You also haven't said what version of VB you're using. This is old VB6 code, but apart from the Sub declaration I believe it should work in later versions.

          Comment

          • theS70RM
            New Member
            • Jul 2007
            • 107

            #6
            Nice one thanks.

            I now have this running in a vb service on one of our servers, it warns us by email when disk levels of selected drives get to certain levels, and also issues warning decreases as the levels drop.

            pretty basic, only the service at the ini, but i will make a gui when i get round to it.


            Andy

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Hey, it's good too hear you got it going alright.

              Just out of curiosity, which technique did you end up using, API or FSO?

              Comment

              • theS70RM
                New Member
                • Jul 2007
                • 107

                #8
                Originally posted by Killer42
                Hey, it's good too hear you got it going alright.

                Just out of curiosity, which technique did you end up using, API or FSO?

                I used the API call.

                Seems to work well, I just have to make sure my service logs on as a network service with sufficient permissions to access the shared drives.



                Cheers

                Comment

                • codefloor
                  New Member
                  • Dec 2014
                  • 1

                  #9
                  Code:
                  Option Explicit
                  Private Declare Function GetDiskFreeSpace Lib “kernel32″ Alias _
                  “GetDiskFreeSpaceA” (ByVal lpRootPathName As String, _
                  lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
                  lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
                  
                  Private Sub Command1_Click()
                  Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Long
                  GetDiskFreeSpace “E:\”, Sectors, Bytes, FreeC, TotalC
                  Me.AutoRedraw = True
                  Me.Print ” Path: C:\”
                  Me.Print ” Sectors per Cluster:” + Str$(Sectors)
                  Me.Print ” Bytes per sector:” + Str$(Bytes)
                  Me.Print ” Number Of Free Clusters:” + Str$(FreeC)
                  Me.Print ” Total Number Of Clusters:” + Str$(TotalC)
                  Total = TotalC * Sectors * Bytes
                  Me.Print ” Total number of bytes in path:” + Str$(Total)
                  Freeb = FreeC * Sectors * Bytes
                  Me.Print ” Free bytes:” + Str$(Freeb)
                  End Sub
                  Last edited by Rabbit; Dec 19 '14, 08:19 PM. Reason: Link removed per forum policy

                  Comment

                  Working...