473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Network Disk Space

107 100+
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
Feb 28 '08 #1
8 2557
jamesd0142
469 256MB
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
Expand|Select|Wrap|Line Numbers
  1. 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
  2.  
if you want my full vb2005 code then post back and i'll add it here.

James
Feb 28 '08 #2
theS70RM
107 100+
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
Feb 28 '08 #3
jamesd0142
469 256MB
Ok this is written in vb 2005...

Expand|Select|Wrap|Line Numbers
  1. 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
  2.     Public Function GetFreeSpace(ByVal Drive As String) As Long
  3.         'returns free space in MB, formatted to two decimal places
  4.         'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")
  5.  
  6.         Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long
  7.         Dim iAns As Long
  8.         iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
  9.              lBytesTotal, lFreeBytes)
  10.         If iAns > 0 Then
  11.             Return BytesToMegabytes(lFreeBytes)
  12.         Else
  13.             Throw New Exception("Invalid or unreadable drive")
  14.         End If
  15.     End Function
  16.     Public Function GetTotalSpace(ByVal Drive As String) As String
  17.         'returns total space in MB, formatted to two decimal places
  18.         'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB")
  19.         Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long
  20.         Dim iAns As Long
  21.         iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
  22.              lBytesTotal, lFreeBytes)
  23.         If iAns > 0 Then
  24.             Return BytesToMegabytes(lBytesTotal)
  25.         Else
  26.             Throw New Exception("Invalid or unreadable drive")
  27.         End If
  28.     End Function
  29.     Private Function BytesToMegabytes(ByVal Bytes As Long) As Long
  30.         Dim dblAns As Double
  31.         dblAns = (Bytes / 1024) / 1024
  32.         BytesToMegabytes = Format(dblAns, "###,###,##0.00")
  33.     End Function
  34.  
I call it like this:
Expand|Select|Wrap|Line Numbers
  1. Dim jkp As Double = GetFreeSpace("\\123.45.678.90\C$") / 1024
  2.             Label5.Text = "DD2: " & Format(jkp, "###,###,##0.00") & " GB"
  3.  
James
Feb 28 '08 #4
Killer42
8,435 Expert 8TB
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...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.   Dim fso As New FileSystemObject
  3.   Dim drv As Drive
  4.   For Each drv In fso.Drives
  5.     With drv
  6.       If .DriveType = Remote Then
  7.         Me.Print .DriveLetter, .DriveType, .AvailableSpace
  8.       End If
  9.     End With
  10.   Next
  11.   Set drv = Nothing
  12.   Set fso = Nothing
  13. End Sub
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.
Feb 29 '08 #5
theS70RM
107 100+
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
Mar 13 '08 #6
Killer42
8,435 Expert 8TB
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?
Mar 13 '08 #7
theS70RM
107 100+
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
Mar 14 '08 #8
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Declare Function GetDiskFreeSpace Lib “kernel32″ Alias _
  3. “GetDiskFreeSpaceA” (ByVal lpRootPathName As String, _
  4. lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
  5. lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
  6.  
  7. Private Sub Command1_Click()
  8. Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Long
  9. GetDiskFreeSpace “E:\”, Sectors, Bytes, FreeC, TotalC
  10. Me.AutoRedraw = True
  11. Me.Print ” Path: C:\”
  12. Me.Print ” Sectors per Cluster:” + Str$(Sectors)
  13. Me.Print ” Bytes per sector:” + Str$(Bytes)
  14. Me.Print ” Number Of Free Clusters:” + Str$(FreeC)
  15. Me.Print ” Total Number Of Clusters:” + Str$(TotalC)
  16. Total = TotalC * Sectors * Bytes
  17. Me.Print ” Total number of bytes in path:” + Str$(Total)
  18. Freeb = FreeC * Sectors * Bytes
  19. Me.Print ” Free bytes:” + Str$(Freeb)
  20. End Sub
  21.  
Dec 19 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Chandra Mohan | last post by:
Hi All, I have a requirement to create the database with data and log files in a different machine on the network. Googling, I got a link which said Mapped drives do not work but UNC paths...
2
by: charles Collin | last post by:
Hi, My SQL server is short on disk space and I need to create a new instance of SQLServer. I had another server running Linux with enough space left so i create a new partition on it and shared...
14
by: David W. Fenton | last post by:
I'm no stranger to this error message, but I have a client who is experiencing it, but, fortunately, without any actual data corruption, and it's driving them made. Their inability to grasp that...
2
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. I have 35 Gigs of disk space free. It doesn't happen...
3
by: Skrol29 | last post by:
Hello, In order to encircle a problem of performance we have with our PHP scripts, we were brought the make the following test. We take a standard HTML page of our site, and we make a copy of...
18
by: NEWSGROUPS | last post by:
I work for a large organization were my team has developed 2 very substantial databases in Access 2000. These databases have been working fine for the last 6 years with minimal issues or problems....
10
by: gary0gilbert | last post by:
An unusual spin to this recurring disk or network error in a Terminal Server environment. Access 2000, Terminal Server 2000, file server is windows 2000. All users have a separate copy of the...
2
by: Lidia | last post by:
Input: A computer name on the internal network Out: Disk space total and remaining on all drives.
1
by: Mike | last post by:
Is there a way to monitor a network drive for the space? I'm looking to create something that will monitor the disk space on a network drive and when it hits a certain level of free space (ie: 200...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.